Paul Lemmens <[EMAIL PROTECTED]> writes:

> Hoi Christoph,
> 
> --On woensdag 4 juni 2003 15:21 +0200 Christoph Lehmann
> <[EMAIL PROTECTED]> wrote:
> 
> > what is the easiest way to get from
> > x
> >      x1 x2
> > [1,]  2  3
> > [2,]  3  2
> > [3,]  1  3
> > [4,]  1  4
> >
> > xbar1
> >        x1 x2
> > [1,] 1.75  3
> > [2,] 1.75  3
> > [3,] 1.75  3
> > [4,] 1.75  3
> >
> > with the mean of the columns of x as values?
> >
> xbar1 <- tapply(as.vector(x), gl(2,4), mean);

No. I think you're missing the point (it gives a 2-vector rather than
a 4x2 matrix, and apply(x,2,mean) is quicker for that). Try

sweep(x,2,apply(x,2,mean),function(x,y)y)


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to