Re: [R] list: index of the element, that is TRUE

2012-01-16 Thread Hadley Wickham
On Mon, Jan 16, 2012 at 10:15 AM, Duncan Murdoch wrote: > On 12-01-16 10:34 AM, Marion Wenty wrote: >> >> Dear People, >> >> I have got the following example for a vector and the index of the TRUE >> element: >> >> Myvector<- c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE) >> which(Myvector) >>

Re: [R] list: index of the element, that is TRUE

2012-01-16 Thread Marion Wenty
> > Thank you all very much for your help! > Yes, the unlist or as.logical command is what I was looking for. Anyway, Duncan, the sapply is also usefull and I might need it some other time. Thanks, Michael, also for the tip that if you get a vector when a list is expected, that the the program w

Re: [R] list: index of the element, that is TRUE

2012-01-16 Thread Ajay Askoolum
Given Mylist <- list(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE) Try which(as.logical(MyList)) to return the indices where Mylist is TRUE. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mai

Re: [R] list: index of the element, that is TRUE

2012-01-16 Thread Duncan Murdoch
On 12-01-16 10:34 AM, Marion Wenty wrote: Dear People, I have got the following example for a vector and the index of the TRUE element: Myvector<- c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE) which(Myvector) Now I would like to find out the same for a list: Mylist<- list(FALSE,FALSE,FALS

Re: [R] list: index of the element, that is TRUE

2012-01-16 Thread R. Michael Weylandt
I'd just unlist it to a vector and use the same methods: a plus of this (I believe) is that if you get a vector when a list as expected, your program will continue to work. Michael On Mon, Jan 16, 2012 at 10:34 AM, Marion Wenty wrote: > Dear People, > > I have got the following example for a vec

Re: [R] list: index of the element, that is TRUE

2012-01-16 Thread David Winsemius
On Jan 16, 2012, at 10:34 AM, Marion Wenty wrote: Dear People, I have got the following example for a vector and the index of the TRUE element: Myvector <- c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE) which(Myvector) Now I would like to find out the same for a list: Mylist <- list(F

[R] list: index of the element, that is TRUE

2012-01-16 Thread Marion Wenty
Dear People, I have got the following example for a vector and the index of the TRUE element: Myvector <- c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE) which(Myvector) Now I would like to find out the same for a list: Mylist <- list(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE) ... Does