Re: [R] add a new column to data frame

2010-10-01 Thread Henrique Dallazuanna
ing that can do this, I guess not possible. > > Thank you > > John > > > > > > From: Phil Spector > > Cc: r-help@r-project.org > Sent: Fri, October 1, 2010 10:58:55 AM > Subject: Re: [R] add a new column to data frame > > Here are two ways:

Re: [R] add a new column to data frame

2010-10-01 Thread array chip
is, I guess not possible. Thank you John From: Phil Spector Cc: r-help@r-project.org Sent: Fri, October 1, 2010 10:58:55 AM Subject: Re: [R] add a new column to data frame Here are two ways: dat0 = subset(dat,time==0) one = as.data.frame(as.table(

Re: [R] add a new column to data frame

2010-10-01 Thread Phil Spector
Here are two ways: dat0 = subset(dat,time==0) one = as.data.frame(as.table(by(dat0,dat0$id, function(x)as.character(x$mode)[which.max(x$y)]))) names(one) = c('id','type') merge(dat,one) two = sapply(split(dat0,dat0$id), function(x)as.character(x$mode)[which.max(