Learn R Programming

umx (version 4.9.0)

umx_is_ordered: Test if one or more variables in a dataframe are ordered

Description

Return the names of any ordinal variables in a dataframe

Usage

umx_is_ordered(
  df,
  names = FALSE,
  strict = TRUE,
  binary.only = FALSE,
  ordinal.only = FALSE,
  continuous.only = FALSE,
  summaryObject = FALSE
)

Arguments

df

A data.frame() or mxData() to look in for ordinal variables (if you offer a matrix or vector, it will be upgraded to a dataframe)

names

whether to return the names of ordinal variables, or a binary (T,F) list (default = FALSE)

strict

whether to stop when unordered factors are found (default = TRUE)

binary.only

only count binary factors (2-levels) (default = FALSE)

ordinal.only

only count ordinal factors (3 or more levels) (default = FALSE)

continuous.only

use with names = TRUE to get the names of the continuous variables

summaryObject

whether to return a nice summary object. Overrides other settings (FALSE)

Value

  • vector of variable names or Booleans

References

See Also

Other Check or test: umx_check_names(), umx_is_class(), umx_is_endogenous(), umx_is_exogenous(), umx_is_numeric(), umx

Examples

Run this code
# NOT RUN {
x = data.frame(ordered(rbinom(100,1,.5))); names(x) = c("x")
umx_is_ordered(x, summaryObject= TRUE) # all ordered factors including binary
tmp = mtcars

tmp$cyl = ordered(mtcars$cyl) # ordered factor
tmp$vs = ordered(mtcars$vs) # binary factor
umx_is_ordered(tmp) # true/false
umx_is_ordered(tmp, strict=FALSE)
umx_is_ordered(tmp, names = TRUE)
umx_is_ordered(tmp, names = TRUE, binary.only = TRUE)
umx_is_ordered(tmp, names = TRUE, ordinal.only = TRUE)
umx_is_ordered(tmp, names = TRUE, continuous.only = TRUE)
umx_is_ordered(tmp, continuous.only = TRUE)

x = umx_is_ordered(tmp, summaryObject= TRUE)

isContinuous = !umx_is_ordered(tmp)
# }
# NOT RUN {
# nb: By default, unordered factors cause a message...
tmp$gear = factor(mtcars$gear) # Unordered factor
umx_is_ordered(tmp)
umx_is_ordered(tmp, strict = FALSE) # compare: no warning

# also: not designed to work on single variables...
umx_is_ordered(tmp$cyl)
# Do this instead...
umx_is_ordered(tmp[, "cyl", drop= FALSE])
# }

Run the code above in your browser using DataLab