Skip to content

Instantly share code, notes, and snippets.

@inkhorn
Created April 29, 2012 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inkhorn/2523200 to your computer and use it in GitHub Desktop.
Save inkhorn/2523200 to your computer and use it in GitHub Desktop.
Max Function that Returns NA when vector is full of NAs
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