How to compare values in each list object, then output corresponding matching values with the indices of list objects that have corresponding values?

I'd like to compare the values of all the different list objects and then output or record the matching values with corresponding list object indices that have the matching value in program R.

Here is the code:

a <- c(10,23,50,7,3) 
b <- c(1,1,2,2,3) 
c <- c(33,24,4,10,1) 
d <- c(1,4,7,8,3) 
y <- c() 
z <- c() 
r <- list() 
table <- data.frame(a,b,c,d) 

for (i in 1:5){   for (j in 3:4){
    x <-  table$b[j] 
    for (l in which(table$b == x)){
      if (abs((table$c[j] - table$a[i])-table$d[l])<10)
      {y <- rbind(y, table[j,])}}
    z <- y}   y <- c()   r[[i]] <- z}

The output:

> r
[[1]]
   a b  c d
4  7 2 10 8
41 7 2 10 8

[[2]]
NULL

[[3]]
NULL

[[4]]
   a b  c d
4  7 2 10 8
41 7 2 10 8

[[5]]
    a b  c d
3  50 2  4 7
31 50 2  4 7
4   7 2 10 8
41  7 2 10 8

I'd like to record the matching values between list objects and also the indices of the list objects that have these matching values. For example in this instance r[[1]] and r[[4]] have matching vector value 7 2 10 8 , I'd like to write in the data frame both the vector and the indices of list object that have this value. How to do this?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.