[R] How to or or and all the values in a logical vector?

Chi Yau chi.yau at r-tutor.com
Sat Sep 5 22:54:58 CEST 2009


Try this:

# Use cummin for 'and'
>  x <- c(TRUE, TRUE, FALSE, TRUE)
> cummin(x) == TRUE    # the last element below is the result you want
[1]  TRUE  TRUE FALSE FALSE


# Use cummax for 'or'
> y <- c(FALSE, FALSE, TRUE, FALSE)
> cummax(y) == TRUE    # the last element below is the result you want
[1] FALSE FALSE  TRUE  TRUE




David Winsemius wrote:
> 
> 
> On Sep 4, 2009, at 10:37 PM, Peng Yu wrote:
> 
>> Hi,
>>
>> Suppose I have a logical vector x, I want to compute the 'and'
> 
> ?all
> 
>> and
>> 'or'
> 
> ?any
> 
>> of all its element (the result should be a single value TRUE or
>> FALSE). I have read the R-intro.pdf logical vector section, but I
>> don't find the answer.
> 
> I couldn't find them either.
> 
>> Can somebody let me know how to do it?
>>
>>> x= rep(TRUE, 3)
>>
>> Regards,
>> Peng
> 
> -- 
> 
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> ______________________________________________
> 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.
> 
> 


-----
Chi Yau
http://r-tutor.com http://r-tutor.com 


-- 
View this message in context: http://www.nabble.com/How-to-or-or-and-all-the-values-in-a-logical-vector--tp25304562p25312249.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list