Description Usage Arguments Value Author(s) Examples
Gives "no" and "yes" response option labels to variables.
1 |
dat |
the data frame |
vars |
a single variable or a list of multiple variables |
ros |
0 denotes that the values are 0 (no) and 1 (yes); 1 denotes that the values are 1 (no) and 2 (yes) |
ord |
logical indicating whether the items should be ordinal (TRUE) or factor (FALSE:Default) |
This function will return response option labels for ordered factors.
Seth Berry, Michael Clark
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function(dat, vars, ros, ord=FALSE){
require(dplyr)
datReduced = select(dat, one_of(vars))
if(ros == 0)
likOrd = lapply(datReduced, function(x)
factor(x,
levels = c(0,1),
labels = c("No", "Yes"),
ordered=ord)
)
else {
datReduced = select(dat, one_of(vars))
likOrd = lapply(datReduced, function(x)
factor(x,
levels = c(1,2),
labels = c("No", "Yes"),
ordered=ord)
)
}
likOrd = as.data.frame(likOrd)
dat[,vars] = likOrd
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.