小编ari*_*888的帖子

在函数内部使用dplyr时出错

我正在尝试组合一个函数,从我的原始数据框创建一个子集,然后使用dplyr的SELECT和MUTATE根据萼片/花瓣的宽度和长度的总和给出我的大/小条目的数量.

filter <- function (spp, LENGTH, WIDTH) {
  d <- subset (iris, subset=iris$Species == spp) # This part seems to work just fine
  large <- d %>%                       
    select (LENGTH, WIDTH) %>%   # This is where the problem arises.
    mutate (sum = LENGTH + WIDTH) 
  big_samples <- which(large$sum > 4)
 return (length(big_samples)) 
}
Run Code Online (Sandbox Code Playgroud)

基本上,我希望函数返回大花的数量.但是,当我运行该函数时,我得到以下错误 -

filter("virginica", "Sepal.Length", "Sepal.Width")

 Error: All select() inputs must resolve to integer column positions.
The following do not:
*  LENGTH
*  WIDTH 
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

r function dplyr tidyeval

14
推荐指数
3
解决办法
5610
查看次数

标签 统计

dplyr ×1

function ×1

r ×1

tidyeval ×1