Home > Software design >  How to use R to make sure an item is present in all 3 lists?
How to use R to make sure an item is present in all 3 lists?

Time:10-05

We have three places were we keep our records for our mice cages' numbers in our lab:

  1. Website for university where they bill us
  2. Personal excel sheet
  3. Website for our whole lab

I'm trying to organize them to make sure every entry is present in all three places and not missing from one of them.

Is there a way to give me which cage number is present in all three, and which is present in only one or two?

CodePudding user response:

If we need to know numbers that are present in all, intersect is good

Reduce(intersect, lst1)

where lst1 is a list of three vectors. To find the count of elements that are present, unlist the list elements and get the frequency count with table

table(unlist(lst1))

If we need to know which item is present or not, stack on a named list and get the table

table(stack(setNames(lst1, seq_along(lst1))))
  • Related