【发布时间】:2020-08-21 04:43:47
【问题描述】:
我在 R 中需要一些非常简单的帮助。我定义了一个函数来执行一些操作,但在使用输入参数调用函数时我无法选择变量。
例如:使用mpg数据集仅供参考,我需要过滤掉所有disp> 2.0的列
mpg
#Defining a simple function called select_fun
select_fun <- function(x)
{
a <- mpg %>% filter(x > 2)
return(a)
}
select_fun("disp")
Output:
<chr> model disp year cyl trans drv cty hwy class
audi a4 1.8 1999 4 auto(l5) f 18 29 p compact
audi a4 1.8 1999 4 manual(m5) f 21 29 p compact
audi a4 2.0 2008 4 manual(m6) f 20 31 p compact
audi a4 2.0 2008 4 auto(av) f 21 30 p compact
audi a4 2.8 1999 6 auto(l5) f 16 26 p compact
audi a4 2.8 1999 6 manual(m5) f 18 26 p compact
audi a4 3.1 2008 6 auto(av) f 18 27 p compact
输出不正确,因为过滤后的值仍然存在。 也许我错过了一些非常简单和愚蠢的东西! 任何帮助将非常感激 谢谢!!
【问题讨论】: