使用for循环从列表中提取data.frames [英] Extracting data.frames from a list using for loop

查看:82
本文介绍了使用for循环从列表中提取data.frames的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,并且设法使用以下方法为第一个矩阵 t 提取了一个data.frame:

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)

}

谢谢

推荐答案

这应该

for (i in c("t","ws","wdir","hs","tp","tz","mdir")) {
  assign(paste0("forecast_",i),as.data.frame(forecast[[i]]))
}

这篇关于使用for循环从列表中提取data.frames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆