Johanna Sörensen
Johanna Sörensen

Reputation: 111

Dynamic selection of data frame

I have several data frames (or actually xts objects) that are named x_10min, x_h, x_d, x_w, as they have different time steps (10 minutes, hours, days, weeks). I would like to dynamically select the data frames in a simple for loop. Can I do this? How? I only find information on how to dynamically select columns, but I want to select the whole data frame.

Here is an example of what I have tried so far.

timestep <- c("10min","h","d","w")
for (ts in 1:4) {
   x_mod <- SOMEFUNCTION???(paste("x_", timestep[ts], sep=""))
   # ...
   # and then I use x_mod in my model
   # ...
}

Upvotes: 0

Views: 192

Answers (1)

fmarm
fmarm

Reputation: 4284

You are looking for the get function

timestep <- c("10min","h","d","w")
for (ts in 1:4) {
   x_mod <- get(paste("x_", timestep[ts], sep=""))
   # ...
   # and then I use x_mod in my model
   # ...
}

Upvotes: 2

Related Questions