Hello all,
I could use some help trying to create a for loop. In this simple demo, I have 4 scores in a vector called y. I want to repeatedly draw samples of size n=2 from y, find the mean of these two drawn scores, and save this mean in the output vector. Rinse and repeat until all possible combinations of scores have been exhausted. This code half works; the problem is it only produces 4 means and I'm not sure how to tell it to keep repeatedly sampling until it has all combinations (e.g. 2/2, 2/4, 2/6, 2/8; 4/2, 4/4, 4/6....etc.).
Any help would be appreciated
y=c(2,4,6,8)
output <- vector("double", length=16)
for (i in y) { # 2. sequence
output[[i]] <- mean(sample(y,size = 2,replace = TRUE)) # 3. body
}