我正在尝试组合一个函数,该函数从我的原始数据框创建一个子集,然后使用 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))
}
基本上,我希望函数返回大花的数量。但是,当我运行该函数时,出现以下错误 -
filter("virginica", "Sepal.Length", "Sepal.Width")
Error: All select() inputs must resolve to integer column positions.
The following do not:
* LENGTH
* WIDTH
我究竟做错了什么?