我在R语言的循环方面还比较新手。我想要遍历按顺序编号的数据框,以便对它们执行某个操作。
这些数据框名为total,按顺序从1到15编号:
total1
total2
total3
我希望能从循环中简单地找出如何打印这些对象的名称,以便我可以将其用作执行其他操作的起点。目前我所做的只是:
```python for obj in objects: print(obj) ```
etc.
for (n in 1:15)
{print total[n]
}
但是我一直收到错误提示。
Error: object 'total' not found
我做错了什么?我已经创建好了所有的数据框。
ls(pattern='total\\d+')
或者使用cat
包装,可以使用以下代码:cat(ls(pattern='total\\d+'), sep="\n")
。 - akrunfor(n in 1:15) print(paste0('total', n))
- akrunmget
来返回一个列表。lst <- mget(ls(pattern='total\\d+')); lapply(lst, transform, newCol=V1*8)
- akrun