A vector isn't the right tool here. For your purpose you need another container-like structure called list
. Suppose you have the names of your dataframes stored in a vector called dataframeNames
. Otherwise, create it. The function paste0
concatenates vectors without spacing and coerces all objects in the function-call to characters.
dataframeNames <- paste0('df', 1:10)
Now you need to store your dataframes in a list. This can be done via an lapply
. This function applies a given function (in our case a function that takes a name of an object in the current environment and grabs it) to every element of a container-like structure (in our case the character-vector of names) and stores everything in a list.
dataframeList <- lapply(dataframeNames, function(nam) get(nam))
To access these dataframes as list-elements, you can call them by their name or by indexing via double-square brackets.
dataframeList[[1]] #returns the first dataframe
dataframeList[[7]] #returns the seventh dataframe
dataframeList$df7 #returns the seventh dataframe too