使用字符串作为dplyr中的过滤器? [英] Use string as filter in dplyr?
本文介绍了使用字符串作为dplyr中的过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用字符串变量作为dplyr中的过滤器参数?例如:
Is there a way to use a string variable as the filter argument in dplyr? For example:
filter(iris,Sepal.Length > 6)
将替换为
string <- 'Sepal.Length > 6'
filter(iris,string)
基本上,我正在寻找整个过滤器字符串是一个变量,因为我正在实用地创建过滤器字符串。谢谢您的帮助。
Basically, I am looking for the entire filter string to be a variable as I am creating the filter string pragmatically. Thanks for any help.
推荐答案
如果要使用字符串参数进行过滤,则需要使用 filter _()
而不是 filter()
If you want to filter with a string argument, you'll need to use filter_()
instead of filter()
string <- 'Sepal.Length > 6'
filter_(iris, string)
也请注意,建议使用<编程时code> * _()函数。
Also note that it's recommended to use the *_()
functions when programming.
这篇关于使用字符串作为dplyr中的过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文