I am struggling with variable labels of data.frame columns. Say I have the following data frame (part of much larger data frame):
data <- data.frame(age =
If your vector of labels matches the order of your data.frame columns, but isn't a named vector (so can't be used to subset data.frame columns by name like the lapply approach in the other answer), you can use a for-loop:
for(i in seq_along(data)){
Hmisc::label(data[, i]) <- var.labels[i]
}
label(data)
#> age sex
#> "Age in Years" "Sex of the participant"