Reputation: 13
I have been trying to extract multiple patterns in a sequence in a data frame of each row and returning those patterns in a new column. But the problem is i get a list if i use str_extract_all and i don't how to unlist.
I have been trying to use the code at the bottom. The unnest does not work either neither does unlist in mutate function.
dc <- z %>%
mutate(sequence_match = str_extract_all(z$Sequence,
c("R..S", "R..T", "R..Y")))
Upvotes: 0
Views: 1373
Reputation: 389165
You can return one comma-separated string of values.
library(dplyr)
library(stringr)
dc = z %>%
mutate(sequence_match = sapply(str_extract_all(Sequence,
c("R..S", "R..T", "R..Y"), toString)))
Upvotes: 1