Skip to content

Instantly share code, notes, and snippets.

@jwbowers
Last active December 22, 2015 22:18
Show Gist options
  • Save jwbowers/6538670 to your computer and use it in GitHub Desktop.
Save jwbowers/6538670 to your computer and use it in GitHub Desktop.
PS 230 classwork 5 code pieces
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