Created
June 28, 2012 01:22
-
-
Save ajdamico/3008092 to your computer and use it in GitHub Desktop.
binary operators that never return missing values - how to remove NA values from logical tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create the remove NA function | |
no.na <- | |
function( x , value = FALSE ){ | |
x[ is.na( x ) ] <- value | |
x | |
} | |
#full discussion | |
#http://r.789695.n4.nabble.com/binary-operators-that-never-return-missing-values-td4634024.html | |
#usage examples | |
#define two numeric vectors | |
a <- c( 1 , NA , 7 , 2 , NA , 4 ) | |
b <- c( NA , NA , 9 , 1 , 6 , 4 ) | |
a < b #straight, with NAs in results | |
no.na( a < b ) #with NAs defaulting to FALSE | |
no.na( a < b , TRUE ) #with NAs converted to TRUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment