将其转换为符号,然后计算
library(dplyr)
filter(EIA,!!sym(colcol[1]) == aa & !!sym(colcol[2]) == bb & !!sym(colcol[3]) == cc)
例如,当我们评估第一个条件时,我们得到
filter(EIA, !!sym(colcol[1]) == aa)
# length location stype rock dist ftype depth aspect degree drain TWI
#1 len1 loc3 stype2 rock3 dist3 ftype1 depth2 asp2 degree2 drain4 TWI1
数据
EIA <- structure(list(length = structure(c(1L, 3L, 2L, 3L, 3L, 3L),
.Label = c("len1", "len2", "len4"), class = "factor"), location = structure(c(2L,
1L, 1L, 1L, 1L, 2L), .Label = c("loc2", "loc3"), class = "factor"),
stype = structure(c(2L, 2L, 2L, 2L, 1L, 2L), .Label = c("stype1",
"stype2"), class = "factor"), rock = structure(c(2L, 2L,
1L, 2L, 2L, 1L), .Label = c("rock2", "rock3"), class = "factor"),
dist = structure(c(3L, 1L, 1L, 2L, 1L, 1L), .Label = c("dist1",
"dist2", "dist3"), class = "factor"), ftype = structure(c(1L,
3L, 3L, 3L, 2L, 2L), .Label = c("ftype1", "ftype2", "ftype4"
), class = "factor"), depth = structure(c(1L, 2L, 2L, 2L,
2L, 2L), .Label = c("depth2", "depth3"), class = "factor"),
aspect = structure(c(2L, 3L, 1L, 3L, 1L, 3L), .Label = c("asp1",
"asp2", "asp4"), class = "factor"), degree = structure(c(1L,
2L, 1L, 1L, 2L, 2L), .Label = c("degree2", "degree3"), class = "factor"),
drain = structure(c(2L, 2L, 2L, 2L, 2L, 1L), .Label = c("drain1",
"drain4"), class = "factor"), TWI = structure(c(1L, 3L, 2L,
2L, 2L, 2L), .Label = c("TWI1", "TWI2", "TWI3"), class = "factor")),
class = "data.frame", row.names = c("1", "2", "3", "4", "5", "6"))
colcol <- c("length", "location", "dist")
aa <- "len1"
bb <- "loc2"
cc <- "stype1"