Skip to content

filling a vector with a tapply function applied to another vector

6 messages · albechan, Santosh Srinivas, Dennis Murphy +1 more

#
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
#
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:
#
The first column has 331 rows, the number of factors in the second column is
20 repeated in order to have 331 rows too. What I need is to reapeat in the
third column each of the 20 results derived from
tapply(firstcolumn,secondcolumn,mean) as many times as each factor appears
in the second column. So I'll have 331 values in the third column as well. 
I hope it's clear enough what I need to do.
#
Hi

Use ave instead of tapply. It is designed for such task

Regards
Petr
r-help-bounces at r-project.org napsal dne 12.11.2010 10:49:17:
vector
column is
the
appears
well.
http://r.789695.n4.nabble.com/filling-a-vector-
http://www.R-project.org/posting-guide.html