# [R] saving result of a "for" loop

Alex99 loyola9988 at yahoo.com
Thu Oct 16 15:10:58 CEST 2008

```
Hi everyone,
I have dataset which I take random samples of it 5 times. each time I get
the mean for rows for each sample.
at the end I need to calculate the Average of all means for  each sample and
each row. to clear it up I give an example:
say this is my dataset.
X8 X9X10X12 X13 X14 X15 X16X17X18X19 X20 X21 X22
s1  0  1   0    0    0    1    0    0    0    0    0    0    0    0
s2  0  0   0    0    1    0    0    0    0    0    0    0    1    0
s3  0  1   0    0    0    0    0    0    0    0    0    0    1    0
s4  1  0   0    0    1    0    0    0    0    1    0    0    0    0

I get a random sample and mean of row for that sample(5 times , but I just
put 2 of them here to give you   an idea)

X12 X9 X10
s1    0  1   0
s2    0  0   0
s3    0  1   0
s4    0  0   0
s1        s2        s3        s4
0.3333333 0.0000000 0.3333333 0.0000000

X10 X18 X8
s1    0    0  0
s2    0    0  0
s3    0    0  0
s4    0    1  1
s1        s2        s3        s4
0.0000000 0.0000000 0.0000000 0.6666667

This is the code I used:
for(i in 1:5)
{
temp<-sample(A3,3, replace=F)
Avg=rowMeans(temp)
show(temp)
show(Avg)
}

Now, the problem is how can I save the result for each row(s1,s2,s3,s4) so
that I can get the grand average from 5 runs?I thought about using a vector
in the "for" loop but it's no good, it over right so basically I only get
the means for last sample. any idea how to do it?
Thanks a lot

--
View this message in context: http://www.nabble.com/saving-result-of-a-%22for%22-loop-tp20013519p20013519.html
Sent from the R help mailing list archive at Nabble.com.

```