albechan
2010-Nov-12 08:41 UTC
[R] filling a vector with a tapply function applied to another vector
I have a data frame with three columns. The first one is filled with factors, the second one with numeric values and the third one is an empty vector. I need fill the third column with the results of the function tapply(secondcolumn,firstcolumn,mean) so that I have for each row of the third column the mean of the second column conditional to the factor element in the first column. Thank you very much for your help. Alb -- View this message in context: http://r.789695.n4.nabble.com/filling-a-vector-with-a-tapply-function-applied-to-another-vector-tp3039271p3039271.html Sent from the R help mailing list archive at Nabble.com.
Santosh Srinivas
2010-Nov-12 08:54 UTC
[R] filling a vector with a tapply function applied to another vector
You could just create a new data frame with the result and cbind? On Fri, Nov 12, 2010 at 2:11 PM, albechan <alberto.casetta at satt.biz> wrote:> > I have a data frame with three columns. The first one is filled with factors, > the second one with numeric values and the third one is an empty vector. > I need fill the third column with the results of the function > tapply(secondcolumn,firstcolumn,mean) so that I have for each row of the > third column the mean of the second column conditional to the factor element > in the first column. > Thank you very much for your help. > Alb > -- > View this message in context: http://r.789695.n4.nabble.com/filling-a-vector-with-a-tapply-function-applied-to-another-vector-tp3039271p3039271.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >