test <- c(1,2,0,5,0)
which(test == 0)
test %>% which(.==0)
test %>% which(,==0)
test %>% which( ==0)
我正在try 找出如何通过管道将向量传递给Which()函数.使用哪个(test==0)可以得到想要的结果,但是在最后三行使用管道都会产生错误.我如何才能获得与使用管道相同的结果(test==0)?
test <- c(1,2,0,5,0)
which(test == 0)
test %>% which(.==0)
test %>% which(,==0)
test %>% which( ==0)
我正在try 找出如何通过管道将向量传递给Which()函数.使用哪个(test==0)可以得到想要的结果,但是在最后三行使用管道都会产生错误.我如何才能获得与使用管道相同的结果(test==0)?
使用{...}以防止点插入which
中. 如果没有大括号,它将像which(., . == 0)
中那样插入点作为第一个参数.
library(dplyr)
test %>% { which(. == 0) }
## [1] 3 5
对于Magrittr,我们可以使用equals
library(magrittr)
test %>% equals(0) %>% which
## [1] 3 5
要使用|>;,请创建一个包含test
的列表,其中组件名称为点.
test |>
list(. = _) |>
with(which(. == 0))
## [1] 3 5