Re: [R] ask a question about list in R project

From: song song <rprojecthelp_at_gmail.com>
Date: Mon, 28 Jun 2010 22:09:11 -0700

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_at_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. Received on Tue 29 Jun 2010 - 05:11:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jun 2010 - 07:00:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive