R 中与管道一起使用的“c()”函数的替代方案?

Jul*_*ien 2 r dplyr tidyverse

c()与管道运算符一起使用的解决方法是添加大括号

library(dplyr)

mtcars %>% {
  c(.$mpg, .$cyl)
}
Run Code Online (Sandbox Code Playgroud)

但它并不漂亮。

cR 中使用管道的函数是否有替代方案?

library(dplyr)

mtcars %>% 
  alternative_c(.$mpg, .$cyl) # Does such a function exist?
Run Code Online (Sandbox Code Playgroud)

ste*_*fan 5

使用magrittr博览会管道%$%你可以这样做:

library(magrittr)

mtcars %$% c(mpg, cyl)
#>  [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
#> [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
#> [31] 15.0 21.4  6.0  6.0  4.0  6.0  8.0  6.0  8.0  4.0  4.0  6.0  6.0  8.0  8.0
#> [46]  8.0  8.0  8.0  8.0  4.0  4.0  4.0  4.0  8.0  8.0  8.0  8.0  4.0  4.0  4.0
#> [61]  8.0  6.0  8.0  4.0
Run Code Online (Sandbox Code Playgroud)