Skip to content

Instantly share code, notes, and snippets.

@henchc
Created July 18, 2017 19:07
Show Gist options
  • Save henchc/32944fbf49e80e56a7549d72aa87f961 to your computer and use it in GitHub Desktop.
Save henchc/32944fbf49e80e56a7549d72aa87f961 to your computer and use it in GitHub Desktop.
flatten nested lists from jsonLITE (e.g. for CSV export) in R. This will join the nested lists with a semicolon separator.
f <- function(df) {
for (col in names(df)) {
if (is.list(df[[col]])) {
i <- 1
for (row in df[[col]]) {
df[[col]][i] <- paste(row, collapse = '; ')
i <- i + 1
}
df[[col]] <- unlist(df[[col]])
}
}
return (df)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment