I have a loop where I change values. I need to take a sequentially named data frame and assign it to a variable:
for(i in 1:n){
static <- paste('dinamic' , i , sep = '')
# more code...
}
In other words, I would like the code to resolve to:
static <- dynamic1 # when i = 1, and so forth
You can do this using the get
function:
for (i in 1:n) {
static <- get(paste('dinamic' , i , sep = ''))
# more code...
}
The R documentation about the function.
another way would be to create a empty dataframe and then append your data to with each iteration. Something like below :
df <- NULL
for(i in 1:n){
static <- paste('dinamic' , i , sep = '')
more code...
df <- rbind(df,static)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With