简体   繁体   中英

Create Multiple JSON files from Dataframe R

I have a dataframe and I want to create individual JSON files and use one of the column names to name each of the JSON files.

The following code will create multiple CSV files, but instead I want JSON. I am using the iris dataset from plyr.

library(plyr)
d_ply(iris, .(Species), function(x) write.csv(x, file = paste(unique(x$Species), ".csv", sep = "")))

As Nicola suggests, there are many packages for producing JSON. Adapting your d_ply code:

library(jsonlite)
d_ply(iris, .(Species), function(x) {
    writeLines(toJSON(x), file = paste0(x$Species[1], ".json"))
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM