[R] calculating the mean of a random matrix (by row) and some general questions

RichardLang lang at zedat.fu-berlin.de
Tue Jul 19 22:03:48 CEST 2011

Thanks for your advice!

I found another method to solve my problem (on page 20 of the manual =) ).
Here's my code

# Set n and m to whatever you want
n = 25
m = 10

# Build a random vector (here with exponential distribution) with lenght of
x = rexp(n*m,1)

# Set up a factor in order to group x into pieces each of size ten
y = factor( rep(1:n, each = m) )

# tapply will apply mean to each group..
result = tapply(x,y,mean)

View this message in context: http://r.789695.n4.nabble.com/calculating-the-mean-of-a-random-matrix-by-row-and-some-general-questions-tp3678964p3679186.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list