An R package to play with lists of data.frames.
The purpose of this R package is to transform the names of a list of data.frames into a column of each data.frame. That comes in handy for me in two contexts:
broom
package, tagnfuse
the list and you
are good to go.install.packages("devtools")
devtools::install_github("ALanguillaume/tagnfuse", dependencies = TRUE)
library(tagnfuse)
Example using dummy data.
foo <- list(bonnie = data.frame(dollars = c(100, 200),
bullets = c(3, 4)),
clyde = data.frame(dollars = c(150, 75),
bullets = c(7, 8)))
foo
#> $bonnie
#> dollars bullets
#> 1 100 3
#> 2 200 4
#>
#> $clyde
#> dollars bullets
#> 1 150 7
#> 2 75 8
Tag…
foo %>% tag(label = "gangster")
#> $bonnie
#> dollars bullets gangster
#> 1 100 3 bonnie
#> 2 200 4 bonnie
#>
#> $clyde
#> dollars bullets gangster
#> 1 150 7 clyde
#> 2 75 8 clyde
…and then fuse !
foo %>% tag(label = "gangster") %>% fuse()
#> dollars bullets gangster
#> 1 100 3 bonnie
#> 2 200 4 bonnie
#> 3 150 7 clyde
#> 4 75 8 clyde
Or directly
foo %>% tagnfuse(label = "gangster")
#> dollars bullets gangster
#> 1 100 3 bonnie
#> 2 200 4 bonnie
#> 3 150 7 clyde
#> 4 75 8 clyde
This was an exercice for me to learn R package development. One should
not use this package in production code. dplyr::bind_rows()
or
data.table::rbindlist()
are the state of the art tools for such
operations.
foo %>% dplyr::bind_rows(.id = "gangster")
#> gangster dollars bullets
#> 1 bonnie 100 3
#> 2 bonnie 200 4
#> 3 clyde 150 7
#> 4 clyde 75 8
foo %>% data.table::rbindlist(idcol = "gangster")
#> gangster dollars bullets
#> 1: bonnie 100 3
#> 2: bonnie 200 4
#> 3: clyde 150 7
#> 4: clyde 75 8
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.