更新时间:2023-09-17 23:50:16
之间
没什么特别的,R中的任何其他函数都会导致相同的问题。您的困惑源于dplyr具有许多功能,这些功能使您可以像对待普通变量一样处理data.frame列名;例如:
between
is nothing special — any other function in R would have led to the same problem. Your confusion stems from the fact that dplyr has a lot of functions that allow you to work on data.frame column names as if they were normal variables; for instance:
filter(flights, month > 9)
但是, 之间
不是这些功能之一。如上所述,这只是正常功能。因此,如果要使用它,则需要以常规方式提供参数。例如:
However, between
is not one of these functions. As mentioned, it’s simply a normal function. So if you want to use it, you need to provide arguments in the conventional way; for instance:
between(flights$month, 7, 9)
这将返回逻辑向量,您现在可以使用它来索引您的数据。
This will return a logical vector, and you can now use it to index your data.frame:
flights[between(flights$month, 7, 9), ]
或更像是dplyr:
flights %>% filter(between(month, 7, 9))
请注意,我们现在在此处使用非标准评估。但是评估是由过滤器
执行的,而不是由之间的$code>执行的。使用标准评估调用
之间的
(通过
过滤器
)。
Note that here we now use non-standard evaluation. But the evaluation is performed by filter
, not by between
. between
is called (by filter
) using standard evaluation.