R 无法理解%>;%

R 无法理解%>;%,r,magrittr,R,Magrittr,我很难理解%>% 我需要一个例子来理解这一点。以下是我的简单示例: v <- c("the cat the cat ran up the tree tree", "the dog ran up the up the tree", "the squirrel squirrel ran up the tree") 我希望采取以下行动: v <- gsub('kat', 'cat', v) v <-

我很难理解%>%

我需要一个例子来理解这一点。以下是我的简单示例:

v <- c("the cat the cat ran up the tree tree", "the dog ran up the up the tree", 
         "the squirrel squirrel ran up the tree")
我希望采取以下行动:

v <- gsub('kat', 'cat', v) 
v <- gsub('dogg', 'dog', v) 
v <- gsub('squirrel', 'squirrrel', v)
有人能帮我纠正一下吗

我得到一个错误:

Warning message:
In gsub(., "dogg", "dog", v) :
  argument 'pattern' has length > 1 and only the first element will be used

默认情况下,
管道将把值放入下一个函数的第一个参数中。如果需要将值放置在不同的参数位置,则需要使用特殊的
变量来指示要将其放置的位置。比如说

v %>% 
  gsub('kat', 'cat', .) %>%
  gsub('dogg', 'dog', .) %>%
  gsub('squirrel', 'squirrrel', .)
Warning message:
In gsub(., "dogg", "dog", v) :
  argument 'pattern' has length > 1 and only the first element will be used
v %>% 
  gsub('kat', 'cat', .) %>%
  gsub('dogg', 'dog', .) %>%
  gsub('squirrel', 'squirrrel', .)