样本数据代码
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" ?