Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting dataframe directly from JSON-file?
    primarykey
    data
    text
    <p>First, let me thank everybody who contributes to Stackoverflow and R! I'm one of those R-users who is not so good at programming, but bravely try to use it for work, so the issue below is probably trivial... </p> <p>Here's the problem. I need to import files in JSON-format to R: </p> <pre><code># library(plyr) # library(RJSONIO) # lstJson &lt;- 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 &lt;- 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 &lt;- ldply(txtJson, data.frame) </code></pre> <p>What I need is a data frame similar to this: </p> <pre><code>time object Counter1 Counter2 2011-05-01 17:00 Total 8051 44 2011-05-01 17:15 Total 8362 66 </code></pre> <p>But instead I get </p> <pre><code>"Error in data.frame("2011-05-01 17:00", NULL, check.names = FALSE, stringsAsFactors = TRUE) : arguments imply differing number of rows: 1, 0" </code></pre> <p>I get the same error if I use the lstJson.</p> <p>I'm not sure if <code>RJSONIO</code> is supposed to be "smart enough" to parse files like this, or if I have to manually read the first line of the file, set column-types etc. The reason I'm not using CSV is that I want to "automatically" get dates in date-format, etc.</p> <p>Thanks, /Chris</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload