如何将此API调用转换为R中的数据表?

时间:2018-08-27 20:15:38

标签: r api datatable finance iex

我想将IEX的呼叫转换为R中的数据表:

https://api.iextrading.com/1.0/ref-data/symbols

谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用fromJSON包中的rjson,然后将list转换为data.frame。请参见下面的代码:

library(rjson)
f <- (fromJSON(file = "https://api.iextrading.com/1.0/ref-data/symbols"))
df <- data.frame(t(sapply(f, unlist)), stringsAsFactors = FALSE)
str(df)

输出:

'data.frame':   8691 obs. of  6 variables:
 $ symbol   : chr  "A" "AA" "AAAU" "AABA" ...
 $ name     : chr  "Agilent Technologies Inc." "Alcoa Corporation" "Perth Mint Physical Gold" "Altaba Inc." ...
 $ date     : chr  "2018-09-19" "2018-09-19" "2018-09-19" "2018-09-19" ...
 $ isEnabled: chr  "TRUE" "TRUE" "TRUE" "TRUE" ...
 $ type     : chr  "cs" "cs" "N/A" "cs" ...
 $ iexId    : chr  "2" "12042" "14924" "7653" ...