Skip to content

Latest commit

 

History

History
152 lines (112 loc) · 4.87 KB

README.md

File metadata and controls

152 lines (112 loc) · 4.87 KB

frame

Build Status (Linux) Build Status (Windows) Coverage Status CRAN Status License CRAN RStudio Mirror Downloads

frame is an R package providing a dataset type analogous to a data.frame supporting two major extensions: (1) associate keys with one or more components to each row; (2) use matrix-like objects as columns, including nested datasets.

Installation

Stable version

frame is available on CRAN. To install the latest released version, run the following command in R:

### install.packages("frame") # not yet, actually

Development version

To install the latest development version, run the following:

devtools::install_github("patperry/r-frame")

Usage

Datasets

The dataset type is like a data.frame but it allows matrix-like columns, including sparse matrices and nested datasets.

# dataset with a sparse matrix column
(x <- dataset(age = c(35, 70, 12, 42),
              color = c("red", "blue", "black", "green"),
              set = Matrix::sparseMatrix(i = c(1, 1, 2, 3, 3, 4),
                                         j = c(3, 2, 1, 3, 2, 1),
                                         x = c(2.8, -1.3, 7.1, 0.1, -5.1, 3.8),
                                         dimnames = list(NULL, c("a", "b", "c")))))
#>             ════set═════
#>   age color   a    b   c
#> 1  35 red   0.0 -1.3 2.8
#> 2  70 blue  7.1  0.0 0.0
#> 3  12 black 0.0 -5.1 0.1
#> 4  42 green 3.8  0.0 0.0

# dataset with a dataset column
(y <- dataset(value = rnorm(4), nested = x))
#>              ════════nested════════
#>                        ════set═════
#>        value age color   a    b   c
#> 1  1.2629543  35 red   0.0 -1.3 2.8
#> 2 -0.3262334  70 blue  7.1  0.0 0.0
#> 3  1.3297993  12 black 0.0 -5.1 0.1
#> 4  1.2724293  42 green 3.8  0.0 0.0

Keys

Datasets can have multi-component keys that uniquely identify each row. You can index a dataset just like a data.frame, or you can use key values to extract particular rows.

# set multi-component keys
keys(x) <- keyset(major = c("x", "x", "y", "y"),
                  minor = c(1, 2, 1, 3))

# show the data keys and values
print(x)
#>                         ════set═════
#> major minor │ age color   a    b   c
#> x         1 │  35 red   0.0 -1.3 2.8
#> x         2 │  70 blue  7.1  0.0 0.0
#> y         1 │  12 black 0.0 -5.1 0.1
#> y         3 │  42 green 3.8  0.0 0.0

# index with keys
x[dataset(major = c("y", "x"),
          minor = c(  3,   1)), ]
#>                         ════set═════
#> major minor │ age color   a    b   c
#> y         3 │  42 green 3.8  0.0 0.0
#> x         1 │  35 red   0.0 -1.3 2.8

Citation

Cite frame with the following BibTeX entry:

@Manual{,
    title = {frame: Data with Context},
    author = {Patrick O. Perry},
    year = {2018},
    note = {R package version 0.0.0},
}

Contributing

The project maintainer welcomes contributions in the form of feature requests, bug reports, comments, unit tests, vignettes, or other code. If you'd like to contribute, either

  • fork the repository and submit a pull request;

  • file an issue;

  • or contact the maintainer via e-mail.

This project is released with a Contributor Code of Conduct, and if you choose to contribute, you must adhere to its terms.