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 607049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:19:07+00:00 2026-05-13T17:19:07+00:00

I have experimental data expressed as dicts of key-value pairs for each experiment. A

  • 0

I have experimental data expressed as dicts of key-value pairs for each experiment. A set of related experiments is serialized as a list of these dicts in JSON. This is parseable in in R via the rjson package, but the data is loaded in a form which is challenging to analyze

data <- fromJSON('[{"k1":"v1","k2":"v2"}, {"k1":"v3","k2":"v4"}]')

yields

[[1]]
[[1]]$k1
[1] "v1"

[[1]]$k2
[1] "v2"


[[2]]
[[2]]$k1
[1] "v3"

[[2]]$k2
[1] "v4"

Attempting to turn this into a data.frame directly with as.data.frame(data) yields:

  k1 k2 k1.1 k2.1
1 v1 v2   v3   v4

clearly viewing the the sequence of key/value pairs across all experiments as a flat 1-dimensional list.

What I want is a more conventional table with a row for each experiment, and a column for each unique key:

  k1 k2
1 v1 v2
2 v3 v4

How can I cleanly express this transform in R?

  • 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-13T17:19:07+00:00Added an answer on May 13, 2026 at 5:19 pm

    The l*ply functions can be your best friend when doing with list processing. Try this:

    > library(plyr)
    > ldply(data, data.frame)
      k1 k2
    1 v1 v2
    2 v3 v4
    

    plyr does some very nice processing behind the scenes to deal with things like irregular lists (e.g. when each list doesn’t contain the same number of elements). This is very common with JSON and XML, and is tricky to handle with the base functions.

    Or alternatively using base functions:

    > do.call("rbind", lapply(data, data.frame))
    

    You can use rbind.fill (from plyr) instead of rbind if you have irregular lists, but I’d advise just using plyr from the beginning to make your life easier.

    Edit:

    Regarding your more complicated example, using Hadley’s suggestion deals with this easily:

    > x<-list(list(k1=2,k2=3),list(k2=100,k1=200),list(k1=5, k3=9))
    > ldply(x, data.frame)
       k1  k2 k3
    1   2   3 NA
    2 200 100 NA
    3   5  NA  9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of experimental values. For instance, I have a value of
I have a program that operates on a large set of experimental data. The
I have a bit of code that fits theoretical prediction to experimental data, and
I have a data frame consisting of results from multiple runs of an experiment,
I have a huge data.table in R which contains the result of a experiment:
In the interpreter for my experimental programming language I have a symbol table. Each
Greetings, Basically, I have two vectors of data (let's call it experimental and baseline).
I have a set of 5 values from experiment, E1, ..., E5 and results
I'm trying to make an experimental web application which minimises redundant data. I have
I have some vectors of experimental data that I need to massage, for example:

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.