【发布时间】:2021-10-25 15:33:48
【问题描述】:
我有一个字符串,想将两个小写单词大写。以下完成了我想要的:
library(tidyverse)
"this is a test" %>%
str_replace_all("this", toupper("this")) %>%
str_replace_all("test", toupper("test"))
但是,我想以更有效的方式执行此操作,因为我有很多模式要替换,并且不希望每个模式有单独的行。我考虑过使用map,但是我无法让它正确执行,因为下面的代码会引发错误:
"this is a test" %>%
c("this", "test") %>%
map_chr(~str_replace_all(.x, toupper(.x)))
谁能告诉我如何做到这一点?
【问题讨论】: