Skip to content

Instantly share code, notes, and snippets.

@ashenkin
Created November 29, 2015 10:10
Show Gist options
  • Save ashenkin/17ab85c1afd653d1481a to your computer and use it in GitHub Desktop.
Save ashenkin/17ab85c1afd653d1481a to your computer and use it in GitHub Desktop.
When you want to omit rows in your dataframe that have NA's in particular colums.
na.omit.somecols <- function(data, noNAsInTheseCols, allOutputCols = names(data)) {
# usage: na.omit.somecols(my_dataframe, c("col1", "col2")). You can also supply a vector of names (allOutputCols) if you just want certain columns returned.
completeVec <- complete.cases(data[, noNAsInTheseCols])
return(data[completeVec, allOutputCols])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment