小编Mat*_*teo的帖子

无法在 R 中使用带有基管的特殊 ( ` ) 函数

对于magrittr管道,可以使用反引号 (`)在管道链中包含特殊功能1。例如:

library(magrittr)
c(7, 6, 5) %>% sort() %>% `[`(1)
#> [1] 5

# and

3 %>% `-`(4)
#> [1] -1
Run Code Online (Sandbox Code Playgroud)

是一样的

v <- c(7, 6, 5)
v <- sort(v)
v[1]
#> [1] 5

# and

3 - 4 
#> [1] -1
Run Code Online (Sandbox Code Playgroud)

但是,本机 R 管道|>(还?)不允许这样做。例如:

c(7, 6, 5) |> sort() |> `[`(1)
#> Error: function '[' not supported in RHS call of a pipe

# and

3 |> `-`(4)
#> Error: function '-' not …
Run Code Online (Sandbox Code Playgroud)

r pipe

4
推荐指数
3
解决办法
87
查看次数

标签 统计

pipe ×1

r ×1