重新分配变量名称/标签

时间:2019-01-31 11:38:51

标签: r label hmisc

样本数据代码

    library(Hmisc)
data = data.frame(var=c("one", "two", "three"), outcome = c(5, 12, 4))
data$v1 <- factor(data$var,
                    levels = c("one", "two", "three"),
                    labels = c("red", "blue", "green"))

因此这可以在变量中添加标签,但是还有更好的方法来减少用户出错的可能性吗?例如,如何在我说的地方做到这一点:

"one" = "red", "two" = "blue" ?

0 个答案:

没有答案