str_extract_all: return all patterns found in string concatenated as vector
问题 I want to extract everything but a pattern and return this concetenated in a string. I tried to combine str_extract_all together with sapply and cat x = c("a_1","a_20","a_40","a_30","a_28") data <- tibble(age = x) # extracting just the first pattern is easy data %>% mutate(age_new = str_extract(age,"[^a_]")) # combining str_extract_all and sapply doesnt work data %>% mutate(age_new = sapply(str_extract_all(x,"[^a_]"),function(x) cat(x,sep=""))) class(str_extract_all(x,"[^a_]")) sapply(str