# construct data frame
mydata <- read.table(text="Severity Description
1 Mild
4 Moderate
3 Moderate
2 Mild
1 Severe", header=TRUE)
# recode Severity into a new variable called SevereNew
Recode(Severity, new.vars="SevereNew", old=1:4, new=c(10,20,30,40))
# abbreviated form, replace original with recoded
# another option, the sequence function, to generate list of values
rec(Severity, old=1:4, new=seq(10,40,by=10))
# construct data frame
# recode Description, leave original variable unmodified
Recode(Description, new.vars="DescribeNew",
old=c("Mild", "Moderate", "Severe"), new=c("M", "O", "S"))
# data in a different data frame than mydata
data(datEmployee)
Recode(Gender, old=c("F","M"), new=c("Female","Male"), dframe=datEmployee)
# reverse score four Likert variables: m01, m02, m03, m10
data(datMach4)
Recode(c(m01:m03,m10), old=0:5, new=5:0, dframe=datMach4)
# for four Likert variables, convert any 0 or 1 to missing
data(datMach4)
Recode(c(m01:m03,m10), old=0:1, new="missing", dframe=datMach4)
# for four Likert variables, convert any missing value to 99
data(datMach4)
Recode(c(m01:m03,m10), old="missing", new=99, dframe=datMach4)
Run the code above in your browser using DataLab