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
"_")[,-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: [
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
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
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
5 matches
Mail list logo