I wanted to add value label to a variable in the data frame. However, the variable name is based on substring match result. For example, I tried to look for a variable whose name include string “Gender", so I used the code
mn<-grep("Gender",names(data),value=TRUE)
to locate the variable.
Then I wanted to add value label for that variable, I tried:
data$mn<-factor(data$mn,levels=c(2,3),labels=c("Male","Female"))
but it did not work. Could anybody help me to fix the problem? Many thanks