Skip to content

Instantly share code, notes, and snippets.

@inkhorn
Created April 29, 2012 01:39
Show Gist options
  • 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