Last active
December 22, 2015 22:18
-
-
Save jwbowers/6538670 to your computer and use it in GitHub Desktop.
PS 230 classwork 5 code pieces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(car) | |
# | |
# | |
# | |
gss$dem<-recode(gss$partyid, "c('strong democrat','not str democrat','ind,near dem')=1 ; c('independent','other party')=NA ; NA=NA ; else=0") | |
# | |
# | |
# | |
with(gss,table(partyid,dem,useNA="ifany")) | |
# | |
# | |
# | |
## A way to do this without the car package | |
## gss$dem<-ifelse(gss$partyid %in% c("strong democrat","not str democrat","ind,near dem"),1,0) | |
## gss$dem[is.na(gss$partyid) | gss$partyis=="other party"]<-NA | |
# | |
# | |
# | |
gss_good<-na.omit(subset(gss,select=c("id","hhkids","dem","partyid"))) | |
# | |
# | |
# | |
str(gss_good) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment