Created
July 18, 2017 19:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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