Reputation: 855
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 i
th 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
Reputation: 7839
Assuming all lists have the same length:
lapply(1:length(Thre1), function(i)
Reduce(intersect, list(Thre1[[i]], ..., Thre10[[i]])))
Upvotes: 1