Hi
Use ave instead of tapply. It is designed for such task
Regards
Petr
r-help-boun...@r-project.org napsal dne 12.11.2010 10:49:17:
> albechan
> Odeslal: r-help-boun...@r-project.org
>
> 12.11.2010 10:49
>
> Re: [R] filling a vector with a tapply function applied
Thank you so much! That's exactly what I needed!
much love
--
View this message in context:
http://r.789695.n4.nabble.com/filling-a-vector-with-a-tapply-function-applied-to-another-vector-tp3039271p3039396.html
Sent from the R help mailing list archive at Nabble.com.
___
Hi:
Look into the ave() function - here's a small demonstration:
d <- data.frame(g = factor(rep(LETTERS[1:5], each = 5)),
x = rpois(25, 10))
d$mean <- with(d, ave(x, g, FUN = mean))
head(d, 10)
head(d, 10)
g x mean
1 A 5 8.4
2 A 14 8.4
3 A 10 8.4
4 A 2 8.4
5 A 11 8
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.
You could just create a new data frame with the result and cbind?
On Fri, Nov 12, 2010 at 2:11 PM, albechan 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 c
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
6 matches
Mail list logo