https://github.com/UchidaMizuki/dibble
Dimensional Data Frames
https://github.com/UchidaMizuki/dibble
multidimensional-arrays r tidy-data
Last synced: 4 months ago
JSON representation
Dimensional Data Frames
- Host: GitHub
- URL: https://github.com/UchidaMizuki/dibble
- Owner: UchidaMizuki
- License: other
- Created: 2021-12-22T03:33:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-12T15:36:43.000Z (5 months ago)
- Last Synced: 2024-11-28T19:09:43.674Z (5 months ago)
- Topics: multidimensional-arrays, r, tidy-data
- Language: R
- Homepage: https://uchidamizuki.github.io/dibble/
- Size: 1.6 MB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - UchidaMizuki/dibble - Dimensional Data Frames (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# dibble
[](https://CRAN.R-project.org/package=dibble)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://github.com/UchidaMizuki/dibble/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/UchidaMizuki/dibble?branch=main)A 'dibble' (derived from 'dimensional tibble') is a data frame consisting of arrays with dimension names, known as data cubes.
The columns of the dibbles are classified into dimensions or measures, and the operations on the measures are broadcasted by dimension names.## Installation
``` r
# the released version from CRAN:
install.packages("dibble")# the development version from GitHub:
# install.packages("devtools")
devtools::install_github("UchidaMizuki/dibble")
```## Examples
```{r,message=FALSE,warning=FALSE}
library(dibble)
library(dplyr)
library(tidyr)
```### Broadcasting
```{r}
arr1 <- array(1:6, c(2, 3),
list(axis1 = letters[1:2],
axis2 = letters[1:3]))
arr2 <- array(1:2, 2,
list(axis2 = letters[1:2]))try(arr1 * arr2)
ddf1 <- as_dibble(arr1)
ddf2 <- as_dibble(arr2)ddf1 * ddf2
# You can use broadcast() to suppress the warnings.
broadcast(ddf1 * ddf2,
dim_names = c("axis1", "axis2"))
```### dplyr methods
dibble provides some dplyr methods as follows,
- `as_tibble()`: From tibble package
- `filter()`
- `mutate()`: Experimental
- `rename()`
- `select()` and `relocate()`
- `slice()`: Specify locations (a integer vector) for each dimension### How to build a dibble
#### From a data.frame
```{r}
df <- expand_grid(axis1 = letters[1:2],
axis2 = letters[1:2]) |>
mutate(value1 = row_number(),
value2 = value1 * 2)ddf <- df |>
dibble_by(axis1, axis2)
ddf
# You can access the measures from the dibble with `$`.
ddf$value1df <- expand_grid(tibble(axis1_key = letters[1:2],
axis1_value = 1:2),
tibble(axis2_key = letters[1:2],
axis2_value = 1:2)) |>
mutate(value1 = row_number(),
value2 = value1 * 2)# You can `pack` several columns into one dimension (See `tidyr::pack()`).
df |>
dibble_by(axis1 = c(axis1_key, axis1_value),
axis2 = c(axis2_key, axis2_value),
.names_sep = "_")
```#### From an array with dimension names or a vector
dibble provides some dplyr methods as follows,
```{r}
# from an array with dimension names
arr <- array(1:4, c(2, 2),
list(axis1 = letters[1:2],
axis2 = letters[1:2]))ddf1 <- as_dibble(arr)
# from a vector
ddf2 <- broadcast(1:4,
list(axis1 = letters[1:2],
axis2 = letters[1:2]))arr
ddf1
ddf2
```