【发布时间】:2020-03-27 17:17:24
【问题描述】:
我正在尝试使用 dplyr 包中的 filter 函数从符合条件的数据框中提取行。
我的数据框如下所示:
head(EIA)
length location stype rock dist ftype depth aspect degree drain TWI
1 len1 loc3 stype2 rock3 dist3 ftype1 depth2 asp2 degree2 drain4 TWI1
2 len4 loc2 stype2 rock3 dist1 ftype4 depth3 asp4 degree3 drain4 TWI3
3 len2 loc2 stype2 rock2 dist1 ftype4 depth3 asp1 degree2 drain4 TWI2
4 len4 loc2 stype2 rock3 dist2 ftype4 depth3 asp4 degree2 drain4 TWI2
5 len4 loc2 stype1 rock3 dist1 ftype2 depth3 asp1 degree3 drain4 TWI2
6 len4 loc3 stype2 rock2 dist1 ftype2 depth3 asp4 degree3 drain1 TWI2
等等。总行数:10560
但由于我试图在 for 循环中完成这项工作,过滤函数中的每个元素都必须通过变量(colcol,aa,bb,cc)传递:
colcol
[1] "length" "location" "stype"
aa;bb;cc
[1] "len1"
[1] "loc2"
[1] "stype1"
我尝试过这样的过滤功能,但没有奏效:
filter(EIA, colcol[1] == aa & colcol[2] == bb & colcol[3] == cc)
结果必须提取两行。我认为这是因为 colcol[1] 元素周围的双引号。我尝试使用as.symbol、as.name 和noquote 函数删除这些引号,但它们不起作用。
有没有办法解决这个问题?
提前谢谢你。
【问题讨论】: