Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a list of many dataframes that have the same pattern of names?

let’s say I have these many dataset (let’s imagine 1000 datasets) :

df1 = data.frame(x = 1:10)

df2 = data.frame(x = 2:11)

df3 = data.frame(x = 3:5)

df4 = data.frame(x = 11:20)

I want to create a list that is called L as follows

L = list(df1,df2,df3,df4)

but if I have thousands of dataframes, it would be difficult to write each dataframe namein the list. Would take forever. Would like a function that can make creating this list easier. Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

By using BaseR,

n = 4
L = lapply(1:n, function(x) {get(paste0("df",x)) })

where n is the maximum number at the end of your dataframe names.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading