0

I have a list and I have managed to extract a data.frame for the first matrix "t" using:

forecast_t<-as.data.frame(forecast$t)

I was wondering if it is possible to do it to the rest of the elements using :

for (i in t,ws,wdir,hs,tp,tz,mdir) {
    forecast_i<-as.data.frame(forecast$i)

}

Thank you

Aurèle
  • 12,545
  • 1
  • 31
  • 49
aelbozie
  • 3
  • 3
  • 1
    `platypus`' answer is the way to go to do exactly that, but this is overall a very bad idea. You'll be much better off keeping everything in one list, rather than cluttering your workspace. Something like `lapply(forecast, as.data.frame)` ... – Aurèle Jun 28 '17 at 15:16

1 Answers1

0

this should do it

for (i in c("t","ws","wdir","hs","tp","tz","mdir")) {
  assign(paste0("forecast_",i),as.data.frame(forecast[[i]]))
}
platypus
  • 516
  • 3
  • 8
  • Please see `fortunes::fortune(236)`: _The only people who should use the assign function are those who fully understand why you should never use the assign function._ – Uwe Jun 28 '17 at 15:34