简体   繁体   中英

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.

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. 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")))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM