# NOT RUN {
# get the data, variables Gender plus m01 through m20, 20 Mach IV items
# coded as integers from 0 to 5 on 6-pt Likert scales
mydata <- rd("Mach4", in.lessR=TRUE, quiet=TRUE)
# single variable converted to a factor
mydata <- doFactors(Gender, 0:1, c("Male", "Female"))
# Define the labels
LikertCats <- c("Strongly Disagree", "Disagree", "Slightly Disagree",
"Slightly Agree", "Agree", "Strongly Agree")
# Convert the integer responses to factors for the 20 Mach IV items
mydata <- doFactors(m01:m20, levels=0:5, labels=LikertCats)
# read the data again and this time also the variable labels
mydata <- rd("Mach4", in.lessR=TRUE, quiet=TRUE)
mylabels <- rd("dataMach4_lbl", in.lessR=TRUE)
# convert specified variables to factors according to the given vector
# of three variables only
# leave the original variables unmodified, create new variables
mydata <- doFactors(c(m06, m07, m20), levels=0:5, labels=LikertCats, new=TRUE)
# now copy the variable labels from the original integer variables to the
# newly created factor variables
mylabels <- doFactors(c(m06, m07, m20), var.labels=TRUE)
# }
Run the code above in your browser using DataLab