I found this loop can do this. is there any simple method? rm(list=ls()) a=c(2,3,5,7) mylist=list(c(2,3),5,7)
newlist=list() for (i in 1:4){ for (j in 1:length(mylist)){ newlist[[j]]=mylist[[j]] if (a[i] %in% mylist[[j]]){ newlist[[j]]=mylist[[j]][mylist[[j]]!=a[i]] if (length(newlist[[j]])==0){ newlist[[j]]=NA } } } print(newlist[!is.na(newlist)]) } [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.