Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread Ista Zahn
Hi Mosi, The easiest approach would be be generate native from re and usborn directly, rather than generating dummy codes as an intermediate step: n$native <- interaction(n[c("re", "usborn")]) This has the advantage of preserving the meanings of the levels of native in the resulting factor, so t

Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread arun
"_")[,-5] df3<-df2[as.logical(df2$native),-4] colnames(df3)[3]<- "native"  row.names(df3)<- 1:nrow(df3)  identical(df2New,df3) #[1] TRUE A.K. - Original Message - From: arun To: Mosi Ifatunji Cc: R help Sent: Sunday, September 22, 2013 3:34 PM Subject: Re: [

Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread arun
s")}) library(reshape2) df2<- melt(df1,id.vars=c("re","usborn"))[,-3] colnames(df2)[3]<- "native" A.K. - Original Message - From: Mosi Ifatunji To: "r-help@r-project.org" Cc: Sent: Sunday, September 22, 2013 2:40 PM Subject: [R] C

Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread arun
uot;))[,-3] colnames(df2)[3]<- "native" df2 A.K. - Original Message - From: Mosi Ifatunji To: "r-help@r-project.org" Cc: Sent: Sunday, September 22, 2013 2:40 PM Subject: [R] Coding several dummy variables into a single categorical variable Colleagues, I ha

[R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread Mosi Ifatunji
Colleagues, I have generated several dummy variables: n$native0 <- 1 * (n$re=="white" & n$usborn=="yes") n$native1 <- 1 * (n$re=="afam" & n$usborn=="yes") n$native2 <- 1 * (n$re=="carib" & n$usborn=="yes") n$native3 <- 1 * (n$re=="carib" & n$usborn=="no") I would now like to combine these into a