r-导入不带标题的csv结果为一行;从数据中拆分标头



我是R和R Studio的新手,但我想学习。的结果

GET(
url = "https://api.binance.com",
path = "api/v3/ticker/bookTicker",
) -> BinanceRes
content(BinanceRes, as="parsed")
cat(content(BinanceRes, "text"), sep = "n", file = "BinanceImport2.csv", append = FALSE)

我得到一个csv,编辑器中的内容如下

{"symbol":"ETHBTC","bidPrice":"0.01965100","bidQty":"0.3070000","askPrice":"0.01 965200","askQty":"1.79400000"},{"symbol":000000","askPrice":"0.002217180","taskQty":"4.88000000"},{"symbol":"NEOBTC","bidPrice":"0.00118200","bidQty":"151.84000000","askPrice":"0.00118300","ASKCity":"385.56000000"},…

如何在如下所示的数据帧中重新导入csv?

symbol   bidPrice     bidQty   ... 
ETHBTC   0.01965100   0.307 
LTCBTC   0.006...

我对read.tableread.csv的所有尝试都以只有一行的表或V1到V25xx之类的奇怪事物结束。完全远离访问单个数据。我应该使用哪些关键词进行互联网研究?我所有的结果都有带有标题的csv,而不是这种"垃圾":"随便"的组合。。。

欢迎使用R!这是一个使用dplyr(tidyverse的一部分(的简单解决方案:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(httr)
BinanceRes <- GET(
url = "https://api.binance.com",
path = "api/v3/ticker/bookTicker",
) 
df <- bind_rows(content(BinanceRes))
head(df)
#> # A tibble: 6 x 5
#>   symbol  bidPrice   bidQty       askPrice   askQty      
#>   <chr>   <chr>      <chr>        <chr>      <chr>       
#> 1 ETHBTC  0.01977000 1.81900000   0.01977300 2.91000000  
#> 2 LTCBTC  0.00626500 30.00000000  0.00627000 31.29000000 
#> 3 BNBBTC  0.00219720 16.72000000  0.00219770 0.58000000  
#> 4 NEOBTC  0.00117800 83.67000000  0.00117900 0.16000000  
#> 5 QTUMETH 0.01174000 1.34000000   0.01177300 200.00000000
#> 6 EOSETH  0.01808500 300.00000000 0.01810700 124.12000000

创建于2019-11-03由reprex包(v0.3.0(

相关内容

  • 没有找到相关文章

最新更新