In the R language, I need an operator that returns a | b, except if either a or b is NA and the other one is F.
Currently, F | NA returns NA, I would like it to return F.
This function should work with vectors.
Any idea?
Got it!
myor = function(a,b){
!((is.na(a) & !b) | (is.na(b) & !a) | (!a & !b))
}
> myor(T,T)
[1] TRUE
> myor(T,F)
[1] TRUE
> myor(F,F)
[1] FALSE
> myor(F,NA)
[1] FALSE
> myor(NA,NA)
[1] NA
> myor(T,NA)
[1] TRUE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.