我希望这应该是一个简单的问题.我有几个数据框加载到工作区,标记为df01到df100,而不是所有代表的数字.我想在所有数据集中绘制特定列,例如在方框图中.如何使用globbing引用以df开头的所有对象,即:
boxplot(df00$col1, df02$col1, df04$col1)
=
boxplot(df*$col1)
Run Code Online (Sandbox Code Playgroud)
idomatic方法是使用列表,或使用单独的环境.
您可以使用ls和创建此列表pattern
df.names <- ls(pattern = '^df')
# note
# ls(pattern ='^df[[:digit:]]{2,}')
# may be safer if there are objects starting with df you don't want
df.list <- mget(df.names)
# note if you are using a version of R prior to R 3.0.0
# you will need `envir = parent.frame()`
# mget(ls(pattern = 'df'), envir = parent.frame())
# use `lapply` to extract the relevant columns
df.col1 <- lapply(df.list, '[[', 'col1')
# call boxplot
boxplot(df.col1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
116 次 |
| 最近记录: |