Apply Functions In R
1
1
Entering edit mode
11.2 years ago
sundarrayalu ▴ 10

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 • 3.4k views
ADD COMMENT
2
Entering edit mode

How is your question related to bioinformatics?
To get more informative answer you can trying asking here: http://stackoverflow.com/questions/tagged/r

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
1
Entering edit mode
ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

@ 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?

ADD REPLY
2
Entering edit mode
11.2 years ago
Ido Tamir 5.2k

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

ADD COMMENT
0
Entering edit mode

@ 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

ADD REPLY
1
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1674 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6