Re: [R] adding a dummy variable...

2011-10-04 Thread baptiste auguie
Hi, Using ddply, ddply(df, .(ID), mutate, nrows=length(rel.head), test = nrows==2 & all(rel.head %in% c(1,3))) HTH, baptiste On 5 October 2011 06:02, Dennis Murphy wrote: > Hi: > > Here's another way to do it with the plyr package, also not terribly > elegant. It assumes that rel.head is a f

Re: [R] adding a dummy variable...

2011-10-04 Thread Dennis Murphy
Hi: Here's another way to do it with the plyr package, also not terribly elegant. It assumes that rel.head is a factor in your original data frame: > str(df) 'data.frame': 11 obs. of 2 variables: $ ID : Factor w/ 6 levels "17100","17101",..: 1 1 2 3 4 4 5 5 5 6 ... $ rel.head: Factor w/

Re: [R] adding a dummy variable...

2011-10-04 Thread Martyn Byng
$ID%in%ids) cbind(df,added.dummy) Martyn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of gra...@stat.columbia.edu Sent: 04 October 2011 16:45 To: r-help@r-project.org Subject: [R] adding a dummy variable... Hi all, I have a datas

[R] adding a dummy variable...

2011-10-04 Thread grazia
Hi all, I have a dataset of individuals where the variable ID corresponds to the identification of the household where the individual lives. rel.head stands for the relationship with the household head. so rel.head=1 is the household head, rel.head=2 is the spouse, rel.head=3 is the children. Her