![](/img/trans.png)
[英]How do I get the aggregate number of a variable against another variable in R? Both these variables are non-numeric
[英]How do I create a dummy variable in R with non-numeric data?
我有一列數據,列出了人口普查數據中的各種教育水平,從“ HS等級”到“博士學位”再到“ 9th”,代表該人獲得的最高教育水平。
我想為某人是否受過教育創建一個虛擬變量,在“ educated = YES”類別中,我希望它列出具有大學或職業學校背景的受訪者。 我嘗試使用“&”,但不會將它們分組。
C <- data.frame(educated=census$education=="Assoc-acdm" & "Assoc voc" & "Bachelors" & "Doctorate" & "Masters" & "Prof-school")
有人知道如何對非數字響應進行分組嗎?
相反,您需要:
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.