https://github.com/robertzk/recombinator
R recombinators for turning nested lists into data.frames
https://github.com/robertzk/recombinator
Last synced: 13 days ago
JSON representation
R recombinators for turning nested lists into data.frames
- Host: GitHub
- URL: https://github.com/robertzk/recombinator
- Owner: robertzk
- License: other
- Created: 2015-10-01T22:35:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-14T22:36:02.000Z (about 6 years ago)
- Last Synced: 2024-11-02T16:08:22.190Z (5 months ago)
- Language: R
- Homepage:
- Size: 39.1 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - robertzk/recombinator - R recombinators for turning nested lists into data.frames (R)
README
R recombinators [](https://travis-ci.org/robertzk/recombinator) [](https://coveralls.io/r/robertzk/recombinator)
============An R utility for turning nested lists into data.frames. This can
be useful for turning JSON into R lists, and then into data.frames.Installation
------------The latest stable build can be downloaded from CRAN:
```R
install.packages("recombinator")
```To install the latest development builds directly from GitHub, run this instead:
```R
if (!require("devtools")) install.packages("devtools")
devtools::install_github("robertzk/recombinator")
```Usage
-----There are two supported formats.
* __Homogeneous lists__. A list where the first list element
is a character vector giving the names of the data.frame,
and the subsequent list elements themselves lists of values.
* __Heterogeneous lists__. A list where each element is a named
list of values. In this format, `plyr::rbind` will be used
to take the union of all names and impute the ones missing
with NA values.Here are two examples of the respective format:
```r
recombinator(list(c("a","b","c"), list(1, F, 2), list(2, T, 3)))
# a b c
# 1 1 FALSE 2
# 2 2 TRUE 3recombinator(list(c("a","b","c"), list(1, F, 2), list(2, T, 3)))
# recombinator(list(list(a = 1, b = F, c = 2), list(a = 2, b = T, c = 3)))
# a b c
# 1 1 FALSE 2
# 2 2 TRUE 3# The union of all observed keys is used for column names.
recombinator(list(list(a = 1, b = F, c = 2), list(a = 2, b = T, d = 4)))
# a b c d
# 1 1 FALSE 2 NA
# 2 2 TRUE NA 4
```