Created
April 29, 2012 01:39
-
-
Save inkhorn/2523200 to your computer and use it in GitHub Desktop.
Max Function that Returns NA when vector is full of NAs
This file contains 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
safe.max = function(invector) { | |
na.pct = sum(is.na(invector))/length(invector) | |
if (na.pct == 1) { | |
return(NA) } | |
else { | |
return(max(invector,na.rm=TRUE)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment