简体   繁体   中英

R - Export large dataframe into CSV

Beginner here: I have a list (see screenshot) called Coins_list from which I want to export the second dataframe stored in it called data into a csv. When I use the code

write.csv(Coins_list$data, file = "Coins_list_full_data.csv")

I get a huge CSV with a bunch of numbers from the column named price which apparently containts more dataframes, if I read the output correctly or at least display the data in the price column? How can I export this dataframe into CSV correctly? See screenshot for more details. 截屏

EDIT: I was able to get the first four rows into CSV by using df2 <- Coins_list$data write.csv(df2[1:4,], file="BTC_row.csv") , however it now looks like R puts the price of all four rows within a list c( ) and repeats it in each row? Any idea how to change that?

在此处输入图像描述

(I would post this as a comment but I have too few reputation)

Hey, you could try for starters to flatten the json file by going further than response list$content but looking at what's into the content with another $.

Else you could try getting data$price and see what pops up from there.

something like this:

names = list(data$symbol)

df = data.frame(price = NA, symbol = NA)

for (i in length(data)) {
  
  
  x = data.frame(price = data$price[i], symbol = names[i])
  
  df = inner_join(df, data)
  
  
}

to get a dataframe with price and symbol. I don't know how the data is nested so I'm just guessing.

It would be helpful to know from where you got the data for reproducibility.

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