Trying to build a list of dataframes of variable length.

I am trying to build a list of dataframes of variable length from objects saved in the global environment. These all have the prefix "grid_" followed by a number 1,2,3 etc. There can be varying numbers of these so I want the list to include grid_1:grid_(i). My attempt at a solution to this does not work.

myList <- list(paste0("grid_", 1:i, ","))

This just returns a list of character vectors which do not refer to the dataframe objects.

Can anyone help with a function that will refer to the actual objects and build a list of them using the index (i) ?

Thanks in advance for any help.

You need to use get() to programmatically get the object referred to by a character string

I agree with @nirgrahamuk, but mget() returns a list already. So if you have a number of data frames in the global environment, you can use this code to compile them into a list:

list_of_dfs <- mget(paste0("grid_", 1:i))

Solved. Thanks for your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.