T.Des
T.Des

Reputation: 90

R - Reading vector or dataframe from string

I would like to read a data frame from a string. It is a bit difficult to explain, and, so far I couldn't find the answer anywhere.

Let's imagine I have several data frames: "Param1", "Param2", ... "Param100". I would like to be able to access them from a for loop:

for (i in c(1:100)){
  a <- paste0("Param",i)
  b <- ??? (a)
}

Where b would become "Param1", ... "Param100" when i varies from 1 to 100.

Upvotes: 0

Views: 80

Answers (1)

Josh
Josh

Reputation: 1278

Use get.

for (i in 1:100) {
  b <- get(paste0("Param", i))
}

Upvotes: 2

Related Questions