building a matrix from all iterations in a for-loop that gives a vector results
===

I am running multiple simulations of sampling 20 individuals from villages.  I have a dataset with 2 columns, the first column being the village to which the observation belongs and the second column being 0 for a negative malaria test and 1 for a positive malaria test.  I would like to sample 20 people from each village, repeated 100 times.

I can get the sample to repeat, but I am having trouble taking the results from the loop and putting them into a matrix or data frame.  Here is the code I have so far.  Any help would be appreciated.  Other stacks have suggested creating the matrix beforehand and then adding the resultant vector, but I'm stuck as to how to add the vector.

At the end I would like a matrix with the sampled vector as a column for each iteration of the loop.


> d = read.table("/Users/David/Documents/LQAS study/LQAS data.txt", sep=",", header=TRUE)
> 
> head(d)
  village500 malaria

1         22       0

2         22       0

3          1       1

4         20       0

5          1       0

6         19       0

> 
> villages = split(d$malaria, d$village500)
> 
> for(i in 1:100) {
+ 	sampled = lapply(villages, sample, 20)
+ 	positives = lapply(sampled, sum)
+ 	}