Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:07:34+00:00 2026-05-23T12:07:34+00:00

First, let me thank everybody who contributes to Stackoverflow and R! I’m one of

  • 0

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…

Here’s the problem. I need to import files in JSON-format to 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)  

What I need is a data frame similar to this:

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

But instead I get

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

I get the same error if I use the lstJson.

I’m not sure if RJSONIO 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.

Thanks,
/Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:07:35+00:00Added an answer on May 23, 2026 at 12:07 pm

    Looking at the structure of txtJson you see that all of the useful bits are in txtJson$result$data:

    > sapply( txtJson$result$data, unlist )
         [,1]               [,2]              
    [1,] "2011-05-01 17:00" "2011-05-01 17:15"
    [2,] "Total"            "Total"           
    [3,] "8051"             "8362"            
    [4,] "44"               "66"              
    > t(sapply( txtJson$result$data, unlist ))
         [,1]               [,2]    [,3]   [,4]
    [1,] "2011-05-01 17:00" "Total" "8051" "44"
    [2,] "2011-05-01 17:15" "Total" "8362" "66"
    > as.data.frame(t(sapply( txtJson$result$data, unlist )) )
                    V1    V2   V3 V4
    1 2011-05-01 17:00 Total 8051 44
    2 2011-05-01 17:15 Total 8362 66
    

    In the process of gettting these as unlisted vectors and then passing to ‘as.data.frame’ they are now all class ‘factor’, so there is probably additional effort to re-class() these values. You can instead use:

    data.frame(t(sapply( txtJson$result$data, unlist )) ,stringsAsFactors=FALSE)
    

    And they would all be ‘character’

    As far as importing CSV files, read.table()’s colClasses argument will accept “POSIXlt” or “POSIXct” as known types. The rule I believe is that there must an as._ method available. Here’s a minimal example:

    > read.table(textConnection("2011-05-01 17:00"), sep=",", colClasses="POSIXct")
                       V1
    1 2011-05-01 17:00:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, let me thank you if you're taking the time to look at
Hello everybody let me give you the background first: I'm working on a project
First of all let me say thank you to everyone that offered answers...I have
my first question on Stackoverflow. Let me start with a bit of code. It's
First , I want to thank all the persons who works for this site,
let me be clear first its not like i am trying to build a
Let's assume I have two sites around one DB. The first is based on
First of all i thank the website and the members who helped a lot
I've a not common problem to do a form validation. First let me explain
Let's say I have 2 MS WORD windows, first one is on the left

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.