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.4
6  B 13 11.0
7  B  9 11.0
8  B 10 11.0
9  B 15 11.0
10 B  8 11.0

Hope this is what you're looking for...

Dennis

On Fri, Nov 12, 2010 at 1:49 AM, albechan <alberto.case...@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.
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/filling-a-vector-with-a-tapply-function-applied-to-another-vector-tp3039271p3039337.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to