I am new to dplyr and cannot figure out how to control variables passing through the chain ( %>% ). A simple example: the str_sub function takes three arguments - the first is passed through %>% , but how can I get the last two?
library(stringr) library(dplyr) df <- data.frame(V1 = c("ABBEDHH", "DEFGH", "EFGF", "EEFD"), V2=c(4, 2, 1, 1), V3=c(5, 2, 2, 1), stringsAsFactors=FALSE)
In the R base, I could do:
with(df, str_sub(V1, V2, V3))
and get:
## [1] "ED" "E" "EF" "E"
How to tie this up? - I tried:
df %>% str_sub(V1, V2, V3)
source share