Immer dataframe direkt aus JSON-Datei?

Lassen Sie mich zuerst allen danken, die dazu beiträgt Stackoverflow und R! Ich gehöre zu denen, die R-Nutzer, die nicht so gut in Programmierung, aber tapfer versuchen, es zu benutzen für die Arbeit, also die Frage ist unten wahrscheinlich trivial...

Ist hier das problem. Brauche ich zum importieren von Dateien im JSON-format zu R:

# library(plyr)
# library(RJSONIO)
# lstJson <- fromJSON("JSON_test.json")        #This is the file I read
# dput(lstJson)                                              #What I did to get the txtJson below, for the benefit of testing.

txtJson <- structure(list(version = "1.1", result = structure(list(warnings = structure(list(), class = "AsIs"), fields = list(structure(list(info = "", rpl = 15, name = "time", type = "timeperiod"), .Names = c("info", "rpl", "name", "type")), structure(list(info = "", name = "object", type = "string"), .Names = c("info", "name", "type")), structure(list(info = "Counter1", name = "Counter1", type = "int"), .Names = c("info", "name", "type")), structure(list( info = "Counter2", name = "Counter2", type = "int"), .Names = c("info", "name", "type"))), timeout = 180, name = NULL, data = list( list(list("2011-05-01 17:00", NULL), list("Total", NULL), list(8051, NULL), list(44, NULL)), list(list("2011-05-01 17:15", NULL), list("Total", NULL), list(8362, NULL), list( 66, NULL))), type = "AbcDataSet"), .Names = c("warnings", "fields", "timeout", "name", "data", "type"))), .Names = c("version", "result"))

dfJson <- ldply(txtJson, data.frame)  

Was ich brauche, ist ein Daten-frame ähnlich wie diese:

time  object  Counter1  Counter2  
2011-05-01 17:00  Total  8051  44  
2011-05-01 17:15  Total  8362  66 

Aber stattdessen bekomme ich

"Error in data.frame("2011-05-01 17:00", NULL, check.names = FALSE, stringsAsFactors = TRUE) : 
  arguments imply differing number of rows: 1, 0"

Bekomme ich den gleichen Fehler, wenn ich die lstJson.

Ich bin mir nicht sicher, ob RJSONIO sein soll ist "schlau genug" zu analysieren-Dateien, oder wenn ich manuell Lesen Sie die erste Zeile der Datei, legen Sie Spalten-Typen usw. Der Grund, warum ich nicht mithilfe von CSV ist, dass ich möchte, um "automatisch" Termine im Datum-format, etc.

Dank,
/Chris

InformationsquelleAutor Chris | 2011-06-29
Schreibe einen Kommentar