Skip to content

Instantly share code, notes, and snippets.

@tonglu
Last active December 30, 2015 06:59
Show Gist options
  • Save tonglu/7793347 to your computer and use it in GitHub Desktop.
Save tonglu/7793347 to your computer and use it in GitHub Desktop.
convert null to NA in R(for rubyread)
null_to_na <- function(obj) {
df <- as.data.frame(t(as.data.frame(lapply(lapply(obj, lapply, function(x)ifelse(is.null(x), NA, x)), unlist))))
rownames(df) <- NULL
df
}
dst <- rubyread('defaults_source_tier')
dst2 <- null_to_na(dst)
colnames(dst2) <- c('loan_id', 'dep_var', 'source', 'tier', 'created_at')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment