How to join several lists of characters and count the matching characters in r?

Viewed 16

I have several lists of amino acid sequences. For example: "CASSMGHRGDTQYF" "CASTKGDGANVLTF" "CASRQLSSYEQYF"...

I would like to merge all the lists in a dataframe with 2 columns, one for the characters and one for counts. That is, I want identify matching sequences.

May you help me? I am new to r

Thank you

1 Answers

Maybe something like this?

library(tidyverse)
l <- list(
 list1 = rep(c("CASSMGHRGDTQYF","CASTKGDGANVLTF","CASRQLSSYEQYF"),10),
 list2 = rep(c("CASSMGHRGDTQYF","CASTKGDGANVLTF","CASRQLSSYEQYF"),5)
)
l %>% 
  map_df(~ .x %>% as_tibble %>% rename(amino = 1)) %>% 
           group_by(amino) %>% 
           summarise(count = n())
Related