2021年1月28日星期四

How to use variable labels in an R data frame

I am trying to assign and then use variable labels and then give my work to a novice R programmer who is experienced with SPSS. When the other programmer uses the data, she will want to make tables. She might not remember what h1 is but will know what "Heights in feet" is.

I have assigned the labels. Now how do I use them?

Clarification: Once I have the labels, I want to use the labels the way I would use column names. So in RStudio if I type "heights$", I want to see "Heights in feet" as an option. But I do not want to lose the column name.

library(Hmisc) # variable labels  heights = data.frame(h1 = c(4,5,6, 4), h2 = c(48, 60, 72, 48))  label(heights$h1) = "Heights in feet"  label(heights$h2) = "Heights in inches"  heights    table(heights[[`Heights in feet`]]) # Not correct  table(heights[`Heights in feet`]) # Not correct  table(heights$`Heights in feet`) # Not correct  

Ideas much appreciated.

https://stackoverflow.com/questions/65948815/how-to-use-variable-labels-in-an-r-data-frame January 29, 2021 at 12:32PM

没有评论:

发表评论