我有一个json格式的时间序列数据,我想从json格式中提取数据并将其转换为R中的数据框。我已经安装了rjson和jsonlite包并加载了库。但是,当我运行" fromjson"时,我遇到了以下错误。命令。有谁知道如何解决它?
由于
RCODE
library("rjson", lib.loc="/Users/r_beginer/Library/R/3.0/library")
library("rjsonlite", lib.loc="/Users/r_beginer/Library/R/3.0/library")
test_data=fromJSON(file='/Users/r_beginer/Desktop/logins.json')
Error in is.character(txt) : 'txt' is missing
json格式数据
["2014-03-01 00:01:54", "2014-03-01 00:04:52", "2014-03-01 00:06:03",
"2014-03-01 00:12:11", "2014-03-01 00:14:54", "2014-03-01 00:16:23", "2014-03-01 00:17:19"]
答案 0 :(得分:0)
首先,我想您可能希望致电library(jsonlite)
而不是rjsonlite
。
你的例子不是很容易复制,但是下面的内容适用于我,正如B.Mr.W指出的那样,JSON中应该有这些值的名称。
library(rjson)
no_name <- '["2014-03-01 00:01:54", "2014-03-01 00:04:52", "2014-03-01 00:06:03",
"2014-03-01 00:12:11", "2014-03-01 00:14:54", "2014-03-01 00:16:23", "2014-03-01 00:17:19"]'
write(no_name,"temp.json")
fromJSON(file="temp.json") # returns the correct character array
some_json <- '{"timeStamp":["2014-03-01 00:01:54", "2014-03-01 00:04:52", "2014-03-01 00:06:03",
"2014-03-01 00:12:11", "2014-03-01 00:14:54", "2014-03-01 00:16:23", "2014-03-01 00:17:19"]}'
fromJSON(some_json) # returns a list with one element, $timeStamp, a character array