Skip to main content
Documents
Share
LinkedIn
Facebook
Twitter
Copy
R DocumentationR InterfaceData Input in RData Management in RStatistics in RGraphs in R

Variable Labels in R

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

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

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

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