Stephen Henderson Stephen Henderson - 17 days ago 9
R Question

Create a list of data.frames from a vector of data.frame names

I have code to merge many data.frames using the

Reduce
function- but it requires that I manually input the names of the data.frames into a list. I want to create a list and do it on the fly..

Below
patman.summaries
are data.frames (or
tibble
).

> patman.summaries
[1] "KLEC10.summary" "KLEC11.summary" "KLEC12.summary" "KLEC4.summary" "KLEC5.summary" "KLEC6.summary" "KLEC8.summary" "LEC1.summary" "LEC2.summary" "LEC3.summary"
[11] "LEC7.summary" "LEC9.summary"


However I do not know how to make a list from all of them - my code gives me a list containing only the last
tibble
LEC9.summary


> list(eval(parse(text = patman.summaries)))
[[1]]
# A tibble: 724 × 2
mir_name1 LEC9.summary
<chr> <int>
1 hsa-let-7a-2-3p 8
2 hsa-let-7a-3p 263
3 hsa-let-7a-5p 1518
4 hsa-let-7b-3p 240
5 hsa-let-7b-5p 10358
6 hsa-let-7c-3p 6
7 hsa-let-7c-5p 1495
8 hsa-let-7d-3p 647
9 hsa-let-7d-5p 77
10 hsa-let-7e-3p 39
# ... with 714 more rows


I suppose I can grow this appending within a loop? Is there a direct way please?

Answer

We can use mget to get the values in a list and then apply bind_rows to get a single data.frame

library(dplyr)
mget(patman.summaries) %>% 
                 bind_rows()