Skip to content

Instantly share code, notes, and snippets.

@nelsonauner
Last active September 9, 2015 05:19
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 nelsonauner/74b82300880159686682 to your computer and use it in GitHub Desktop.
Save nelsonauner/74b82300880159686682 to your computer and use it in GitHub Desktop.
Remove NAs only from certain columns with regex
#joinedData is dataframe
# has names(joinedData) > c("BLAH","BLEH","BLUCH","2015-05","2015-06",...)
# want to replce NAs with 0s for date columns
r <- "\\d{4}.\\d{2}"
x <- joinedData[grep(r,names(joinedData))]
x[is.na(x)] <- 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment