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: [
2
#12 carib yes 2
#13 carib yes 2
#14 carib no 3
#15 carib no 3
#16 carib no 3
#17 carib no 3
#18 carib no 3
A.K.
- Original Message -
From: arun
To: Mosi Ifatunji
Cc: R help
Sent: Sunday, September 22, 2013 3:25
Hi,
Try:
set.seed(385)
df<- data.frame(re= sample(c("white","afam","carib"),20,replace=TRUE), usborn=
sample(c("yes","no"),20,replace=TRUE),stringsAsFactors=FALSE)
df1<-within(df,{native3<- 1*(re=="carib" & usborn=="no"); native2<-
1*(re=="carib" & usborn=="yes"); native1<- 1*(re=="afam" & us
4 matches
Mail list logo