我从R中的API接收数据。下面是一个示例答案:
"top3": {
"2015-09-14": 856293,
"2015-09-21": 860175,
"2015-09-28": 855798,
"2015-10-05": 853955,
"2015-10-12": 841631,
"2015-10-19": 837971,
"2015-10-21": 837025,
"2015-10-26": 833868,
"2015-11-02": 831811,
"2015-11-09": 833887,
"2015-11-16": 835176,
"2015-11-23": 807198,
"2015-11-30": 797527,
"2015-12-07": 793526,
"2015-12-14": 815146,
"2015-12-21": 799419,
"2015-12-28": 815103,
"2016-01-04": 813964,
然后我将这些数据传输到数据集。代码如下:
raw_data <- getURL("URL of query")
#Zapisujemy dane w JSon
json_file <- fromJSON(raw_data)
#przerabiamy dane na data set
json_file <- lapply(json_file, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
#Robimy data frame
table_statistics <- as.data.frame(json_file, row.names = NULL)
然后函数str(dataset)
看起来像这样:
'data.frame': 132 obs. of 3 variables:
$ top3 : int 856293 860175 855798 853955 841631 837971 837025 833868 831811 833887 ...
$ top10: int 2152606 2160720 2152531 2159136 2162571 2161058 2124578 2115109 2113461 2112437 ...
$ top50: int 5665937 5681734 5669705 5704516 5719911 5724953 5540973 5453949 5459164 5468059 ...
如何将日期转换为变量?我要做的是创建图形,其中x =日期,y = top3 / top10 / top50。