[英]How do I create a dummy variable in R with non-numeric data?
I have a column of data listing various education levels from census data, they vary from "HS grad" to "Doctorate" to "9th" for the highest level of education the person received. 我有一列数据,列出了人口普查数据中的各种教育水平,从“ HS等级”到“博士学位”再到“ 9th”,代表该人获得的最高教育水平。
I want to create a dummy variable for whether someone is educated or not, and in the "educated=YES" category I want it to list the respondents with college or vocational school backgrounds. 我想为某人是否受过教育创建一个虚拟变量,在“ educated = YES”类别中,我希望它列出具有大学或职业学校背景的受访者。 I've tried using "&" but it won't group them.
我尝试使用“&”,但不会将它们分组。
C <- data.frame(educated=census$education=="Assoc-acdm" & "Assoc voc" & "Bachelors" & "Doctorate" & "Masters" & "Prof-school")
Anyone know how do group non-numeric responses? 有人知道如何对非数字响应进行分组吗?
Instead, you would want: 相反,您需要:
C <- data.frame(educated=(census$education %in% c("Assoc-acdm",
"Assoc voc", "Bachelors", "Doctorate", "Masters", "Prof-school")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.