This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Apply Functions In R

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?

r

Did you try replacing i with 1:1000? Or just deleting i? 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?

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.

1 answer

thelist <- lapply(1:1000, function(i){ ??? })

@ Ido Tamir: Yes, this works but how to store the X prime and Y prime for i=2 and then for i=3 and so on as a list of lists is my question. If you run my original code you get two matrices with bootstrapped values and then I would like to do the same for i= 1:1000 and store them

xy <- list(x=x,y=y)?

Log in to answer this question.