DataCamp R Course

Variable Labels

R's ability to handle variable labels is somewhat unsatisfying.

If you use the Hmisc package, you can take advantage of some labeling features.

label(mydata$myvar) <- "Variable label for variable myvar"

Unfortunately the label is only in effect for functions provided by the Hmisc package, such as describe(). Your other option is to use the variable label as the variable name and then refer to the variable by position index.

names(mydata)[3] <- "This is the label for variable 3"
mydata[3] # list the variable

To Practice

Want to practice more? Try this exercise on variable recoding from DataCamp