Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想要管道的可参数化部分。
这是我要编写的代码:
library(magrittr) d <- data.frame(x=1:5) add_n <- function(n) . %>% transform(x = x + n) d %>% add_n(3)
显然它不起作用,因为%>%设置d为add_n.
%>%
d
add_n
您可以执行以下操作:
add_n <- function(d, n) d %>% transform(x = x + n) d %>% add_n(3) # x # 1 4 # 2 5 # 3 6 # 4 7 # 5 8
%>%将以下函数的第一个参数替换为 LHS,因此您的函数需要第二个参数。