as.vector(do.call(c, lapply(split(x0, y0), mean)))

Test with data generated according to your code:

> phi=NULL
> for (i in 1:length(ind2)){
+   phi[i]=sum(x0[y0==ind1[i]])/ind2[i]
+ }
> phi
[1] -0.18922774  0.36333115 -0.04295032 -0.13892563 -0.03968301  0.33326034
[7]  0.28649576 -0.03786830
> as.vector(do.call(c, lapply(split(x0, y0), mean)))
[1] -0.18922774  0.36333115 -0.04295032 -0.13892563 -0.03968301  0.33326034
[7]  0.28649576 -0.03786830


HTH,
Dennis

On Mon, May 3, 2010 at 10:11 AM, song song <rprojecth...@gmail.com> wrote:

> x0=rnorm(100)
> y0=rpois(100,3)+1
>
> ind=as.data.frame(table(y0))
>
> ind1=ind[,1]
> ind2=ind[,2]
>
> phi=NULL
> for (i in 1:length(ind2)){
>   phi[i]=sum(x0[y0==ind1[i]])/ind2[i]
> }
>
>        [[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.
>

        [[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