I have some patterns
A <- c("A..A","A.A","AA")
B <- c("B..B","B.B","BB")
and some sequences and their freqs in a data.frame
Seq freq
CACCA 1
CAACC 2
BCCBC 3
I need to match the pattern to the seqs, extract and assign the patterns as follow
Seq freq Pattern From
CACCA 1 A..A A
CAACC 2 AA A
BCCBC 3 B..B B
I used grep to match the pattern but it only returns the whole sequence, how can I extract the matched pattern and get the pattern group.
Thank you!