1、测试1
library(dplyr) fun1 <- function(x1, x2){return(x1 - x2)} fun2 <- function(x1, x2, x3){return(x1 * x2 - x3)} a = 8 b = 7 c = 3 y1 <- a %>% fun1(b,.) y1 y2 <- a %>% fun1(.,b) y2 y3 <- a %>% fun2(b,c,.) y3 y4 <- a %>% fun2(.,b,c) y4
##句点的位置代表了管道传进来数据的位置
2、测试2
rm(list = ls()) dat1 <- data.frame(v1 = 1:3, v2 = c("one", "two", "three"), v3 = letters[1:3], v4 = LETTERS[1:3]) dat1 dat2 <- dat1 %>% select(2,4) dat2