hora
hora

Reputation: 855

How to calculate intersect of elements of a list in R

I have 10 lists named : Thre1, Thre2, Thre3, ..., Thre10.

My output should also be a list in a way that ith element of the output should be intersect of ith elements of my input lists so for example:

output[[1]] = Reduce(intersect, 
                     list=(Thre1[[1]],Thre2[[1]],Thre3[[1]],...,Thre10[[1]])

How can I write the code to prevent repeating typing Threi[[j]] by hand?

Upvotes: 0

Views: 786

Answers (1)

Ernest A
Ernest A

Reputation: 7839

Assuming all lists have the same length:

lapply(1:length(Thre1), function(i)
   Reduce(intersect, list(Thre1[[i]], ..., Thre10[[i]])))

Upvotes: 1

Related Questions