Skip to content
Prev 243812 / 398506 Next

Hmisc label function applied to data frame

KT_rfan wrote:
This has nothing to do with Hmisc and corpcor. I things get confusing,
simplify and use str(). 

What you wanted to "label" the columns is "names", or, probably better
named, "colnames". Note that your way of labeling converts the column to a
Class "labelled", which is not what function take for breakfeast.


d = data.frame(x1=runif(10),x2=runif(10))
label(d)  # This alone gives the error message
# x1 x2 
# "" "" "
# Warning message:
#In mapply(FUN = label, x = x, default = default, MoreArgs = list(self =
TRUE),  :
#  longer argument not a multiple of length of shorter
str(d)
# data.frame':   10 obs. of  2 variables:
# $ x1: num  0.1353 0.7234 0.0266 0.074 0.2391 ...
# $ x2: num  0.833 0.573 0.136 0.395 0.308 ...
label(d$x1) = "Variable x1"
str(d)

#'data.frame':   10 obs. of  2 variables:
# $ x1:Class 'labelled'  atomic [1:10] 0.1353 0.7234 0.0266 0.074 0.2391 ...
#  .. ..- attr(*, "label")= chr "Variable x1"
# $ x2: num  0.833 0.573 0.136 0.395 0.308 ...


# Labeling columns, the correct way
d = data.frame(x1=runif(10),x2=runif(10))
str(d)
names(d) = c("Var1","Var2")
str(d)