如何使用管道使用一个对象的一部分

How to use a piece of an object using a pipe

根据 this tutorial,我了解到管道 "take the output of one statement and make it the input of the next statement."

我可以 select 输出的 部分 并将其作为下一条语句的输入吗? 例如,我想知道异常值在这个数据集中的位置:

mtcars$mpg %>% boxplot()$outliers %>% which

谢谢!

你可以使用purrr::pluck()

mtcars$mpg %>% boxplot() %>% purrr::pluck("out")

根据函数的输出类型,您还可以使用[

mtcars$mpg %>% boxplot() %>% .[["out"]]