This loop properly creates 13 df's named bond1,...,bond13 and assigns them the values from function1. Now I need to create 13 more DF's named spread1, ..., spread13 using function2 and two other df's. One of these is fixed for all 13 spreads (DF_B) but for spreadi I need bondi and the second line in the code gives me an error of the following: "Loading required package: tcltk Error in sqliteExecStatement(con, statement, bind.data) : RS-DBI driver: (error in statement: no such table: bond)"
for(i in 1:13)
{
assign(paste("bond", i, sep = ""), function1(DF_A))
assign(paste("spread", i, sep = ""), function2(DF_B, paste("bond", i, sep = "")))
}
What is the proper way to do this?
In function2 you are passing a string as the argument, not your actual data object.
Wrap get(.) around the paste function and you are all set:
function2(DF_B, get( paste("bond", i, sep = "") ) )
Instead, use a list
bond <- vector("list", 13)
spread <- vector("list", 13)
for(i in 1:13)
{
bond[[i]] <- function1(DF_A)
spread[[i]] <- function2(DF_B, bond[[i]])
}
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