Hi,
Could anyone please tell me how "apply" works in R ? For instance I have this data:
X <- data.frame(matrix(rnorm(2000), nrow=10))
colnums_boot <- replicate(1000,sample.int(200,10))
Xprime <- X[,colnums_boot[1:5,i]]
Yprime <- X[,colnums_boot[6:10,i]]
The above for i=1 gives datasets Xprime and Yprime with 10 rows and 5 columns each. How to apply this for i= 1:1000 and obtain 1000 such X primes and Y primes datasets and store as a list?
How is your question related to bioinformatics?
To get more informative answer you can trying asking here: http://stackoverflow.com/questions/tagged/r
Rather than send people elsewhere, why not add the context you think is missing, along with the answer? People use R in bioinformatics all the time, and R forums can be completely obtuse, thus having the freedom to ask an R question in a bioinformatics community can be helpful.
See A brief introduction to “apply” in R
Did you try replacing
i
with1:1000
? Or just deletingi
? You could do this much more cleanly, if you give a clear explanation of what you're trying to do it'll be easier for someone to help.@ Ben : I want 1000 bootstrapped datasets, Xprime having only 5 columns and all rows and Y prime having 5 columns and all rows from the original dataset X . So from the original dataset by bootstrapping there will be 1000 datasets. The above function gives this for i=1. How to do this 1000 times and store the datasets as a list or in other possible ways?