Find immediate neighbors by group using data table or igraph
问题 I have a data.table : groups <- data.table(group = c("A", "B", "C", "D", "E", "F", "G"), code_1 = c(2,2,2,7,8,NA,5), code_2 = c(NA,3,NA,3,NA,NA,2), code_3 = c(4,1,1,4,4,1,8)) group code_1 code_2 code_3 A 2 NA 4 B 2 3 1 C 2 NA 1 D 7 3 4 E 8 NA 4 F NA NA 1 G 5 2 8 What I would like to achieve, is for each group to find the immediate neighbors based on the available codes. For example: Group A has immediate neighbors groups B, C due to code_1 (code_1 is equal to 2 in all groups) and has