ordinalize {modnets} | R Documentation |
Convert continuous variables into ordinal variables
Description
Allows for easy conversion of continuous variables into ordinal variables.
Usage
ordinalize(
data,
m = NULL,
nLevels = 5,
thresholds = NULL,
mthresh = NULL,
mord = TRUE,
minOrd = 3
)
Arguments
data |
An |
m |
The column number or name of the moderator variable, if applicable.
Leave as |
nLevels |
Number of levels for the ordinal variables. |
thresholds |
List of length |
mthresh |
Vector of length |
mord |
if |
minOrd |
The minimum number of unique values allowed for each variable. |
Details
If a moderator value is specified via the m
argument, that variable
will automatically be relegated to the last column of the resultant dataframe
or matrix. It will also be renamed "M"
Value
A dataframe or matrix containing the ordinalized data.
Examples
dat <- data.frame(sapply(1:5, function(z) rnorm(100)))
ord_dat <- ordinalize(dat)
# Including a moderator, without converting the moderator into an ordinal variable
ord_dat <- ordinalize(dat, m = 5, mord = FALSE)
colnames(dat)[5] <- 'M'
ord_dat <- ordinalize(dat, m = 'M', mord = FALSE)
# Use thresholds to break each variable into quartiles
thresh <- lapply(dat, function(z) quantile(z, probs = c(.25, .5, .75)))
ord_dat <- ordinalize(dat, thresholds = thresh)