Home > Blockchain >  How to write this succinctly?
How to write this succinctly?

Time:11-05

Can someone please show me the short way of writing the following lines of R code:

    core_ts0 <- coredata(ts0)
    core_ts1 <- coredata(ts1)
    core_ts2 <- coredata(ts2)
    core_ts3 <- coredata(ts3)
    core_ts4 <- coredata(ts4)
    core_ts5 <- coredata(ts5)

CodePudding user response:

Try this

lst=list()

for (i in 0:5) {
    lst[[paste0("core_ts",i)]]=coredata(get(paste0("ts",i)))
}

list2env(lst,envir=.GlobalEnv)
  •  Tags:  
  • r
  • Related