[R] Calculate Mean of Column Vectors?
Christoph Scherber
Christoph.Scherber at uni-jena.de
Tue Jan 11 11:20:33 CET 2005
Dear Thomas,
My suggestion would be as follows:
y <- rnorm(3000)
dim(y) <- c(3, 1000).
#then create three column vectors out of y using cbind():
w<-cbind(y[1,],y[2,],y[3,])
# and calculate the row means
for (i in 1:1000) z[i]<-mean(w[i,1:3])
z
Hope I got it right!
Regards,
Christoph
Thomas Hopper wrote:
> Hello,
>
> I've got an array defined as y <- rnorm(3000), dim(y) <- c(3, 1000).
>
> I'd like to produce a 1000-element vector z that is the mean of the
> corresponding elements of y (like z[1,1] <- mean(y[1,1], y[2,1],
> y[3,1])), but being new to R, I'm not sure how to do this for all
> elements at once (or, at least, simply). Any help is appreciated.
>
> Thanks,
>
> Tom
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list