【发布时间】:2021-02-22 08:04:45
【问题描述】:
我想在过滤的时候总结一些数据。
它适用于声明的变量,但我不使用符号。
错误是:object of type 'symbol' is not subsettable
我想找到一个解决方法来解决这个问题。
library(datasets)
library(magrittr)
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
data(cars)
cars %<>% as_tibble()
test <- function (.data = NULL, x = NULL, y = NULL) {
xs <- rlang::sym(x)
ys <- rlang::sym(y)
.data %>%
summarise(
sym_work = mean(!!xs),
work = mean(dist[speed == 10]),
not_work = mean(!!xs[!!ys == 10])
)
}
test(.data = cars, x = "dist", y = "speed")
#> Error in xs[!!ys == 10]: objet de type 'symbol' non indiçable
由reprex package (v0.3.0) 于 2020 年 11 月 10 日创建
【问题讨论】: