最佳答案
我使用 mtcar 数据集来说明我的问题。
For example, I want to subset data to 4-cyl cars.I can do:
mtcars %>% filter(cyl == 4)
In my work, I need to pass a string variable as my column name. For example:
var <- 'cyl'
mtcars %>% filter(var == 4)
我也这么做了:
mtcars %>% filter(!!var == 4)
在这两种情况下,我得到了空的数据帧。