I.AH I.AH - 1 year ago 65
R Question

loop in R - Variable with Indices

Hi my Code is like that

for(k in 1:length(t(trd)))


My Code compute all the components of the list Germany. For each "k" I want to safe my list Germany into BondDayk.

As result I Need BondDay1,.., BondDay150 and each of them are lists.

I Need a algo which does:

BondDay1 <- list("Germany")
BondDay2 <- list("Germany")
BondDay3 <- list("Germany")


"Germany" is for each "k" a different dataset.

Thank you

Answer Source

It's clearer. Use:

for (i in 1:150) {
  eval(parse(text = sprintf("BondDay%d <- list(germany)", i)), envir = -1)

If you put that in a function, use envir = -2 instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download