我想使用过滤器和跨函数过滤 iris 数据框,只返回 sepal.length、sepal.width、petal.length 和 petal.width 字段中值大于 2 的行。我有以下代码:
iris%>%
filter(across(c(Sepal.Length, Sepal.Width , Petal.Length, Petal.Width), >2))
报错信息是:Error: unexpected '>' in:
谁能建议修改代码来解决这个问题?
最佳答案
一个可能的解决方案,基于dplyr
:
library(dplyr)
iris%>%
filter(across(is.numeric, ~ .x > 2))
或者:
iris%>%
filter(across(c(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width), ~ .x > 2))
甚至:
iris%>%
filter(across(ends_with(c("Length","Width")), ~ .x > 2))
https://stackoverflow.com/questions/70097359/