简体   繁体   中英

Error when exporting data to CSV in R

I'm getting an error message when exporting data to CSV. The code I'm using is as follows:

library(jsonlite)
energy <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json" %>% 
  fromJSON
file <- c("C://Users//x////sankeyData.txt")
write.table(energy, file, sep="\t")

The error message I'm getting is the following: Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 48, 68

Any ideas on what am I doing wrong?

Thanks

Variable energy is a list of two data frames ( nodes with 48 rows and links with 68 rows). If you want to save this list something like this will work:

file <- c("C://Users//x////sankeyData.rds")
saveRDS(object = energy, file = file)

In case you want two data frames saved then apply function write.table twice for each data frame with different file names.

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