所以我想在%>% way
中堆叠字符串。说,我有一个字符向量
names <- c("Alice","Bob","Charles")
和一个字符串:
phrase <- "Name is "
通常的方法是paste0
:
> paste0(phrase, names)
[1] "Name is Alice" "Name is Bob" "Name is Charles"
有没有办法用%>%
执行此操作?我能够以相反的顺序连接这些:
> names %>% paste0(phrase)
[1] "AliceName is " "BobName is " "CharlesName is "
答案 0 :(得分:5)
您可以尝试:
phrase %>% paste0(names)
哪个给出了
[1] "Name is Alice" "Name is Bob" "Name is Charles"
或者,您可以使用.
:
names %>% paste0(phrase, .)
还会返回:
[1] "Name is Alice" "Name is Bob" "Name is Charles"