将SAS proc格式转换为R [关闭](Convert SAS proc Format to R [closed])
我试图将SAS中的Proc Format语句转换为R.
proc format; value age_f 0='All Ages' 1='18-24' 2='25-34' 3='35-44' 4='45-54' 5='55-64' 6='65+';我已经查看了R中的因子和级别,但我不知道如何实现,所以我可以稍后使用这些类别。
I am trying to convert a Proc Format statement in SAS to R.
proc format; value age_f 0='All Ages' 1='18-24' 2='25-34' 3='35-44' 4='45-54' 5='55-64' 6='65+';I've looked in to the factor and the levels in R, but I am not sure how to implement then so I can use the categories later.
最满意答案
正如StatMethods链接所示,使用factor()方法将值标签与级别对齐:
mydata$age_f <- factor(mydata$age_f, levels = c(0, 1, 2, 3, 4, 5), labels = c("All Ages", "18-24", "25-34", "35-44", "45-54", "55-64"))As the StatMethods link shows, use the factor() method to align value labels to levels:
mydata$age_f <- factor(mydata$age_f, levels = c(0, 1, 2, 3, 4, 5), labels = c("All Ages", "18-24", "25-34", "35-44", "45-54", "55-64"))更多推荐
发布评论