Giter Club home page Giter Club logo

splice's Introduction

splice

Travis build status

splice is an experimental package that brings some capabilities of dplyr::summarise_(all,if,at) to dplyr::summarise() directly.

Installation

You can install from github:

# install.packages("remotes")
devtools::install_github("romainfrancois/splice")

Example

The motivating example was “how do I get the mean of all variables AND the number of observations”.

There are many ways to get just that information, but I wanted to use dplyr::summarise_all() which would get me the means, but not the number of observations.

summarise(!!!all_(...)) is the same as summarise_all(...) but having !!!all_() inside summarise() lets you add other things as well:

library(dplyr, warn.conflicts = FALSE)
library(splice)

iris %>% 
  group_by(Species) %>% 
  summarise(n = n(), !!!all_(mean))
#> # A tibble: 3 x 6
#>   Species        n Sepal.Length Sepal.Width Petal.Length Petal.Width
#>   <fct>      <int>        <dbl>       <dbl>        <dbl>       <dbl>
#> 1 setosa        50         5.01        3.43         1.46       0.246
#> 2 versicolor    50         5.94        2.77         4.26       1.33 
#> 3 virginica     50         6.59        2.97         5.55       2.03

Similarly, if_() and at_():

iris %>%
  summarise(n = n(), !!!if_(is.numeric, mean))
#>     n Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1 150     5.843333    3.057333        3.758    1.199333

iris %>%
  summarise(n = n(), !!!at_(vars(starts_with("Sepal")), mean))
#>     n Sepal.Length Sepal.Width
#> 1 150     5.843333    3.057333

splice's People

Contributors

romainfrancois avatar

Stargazers

Andrew Allen Bruce avatar  avatar John MacKintosh avatar Jimmy Briggs avatar Nicholas Tierney avatar Eduardo Junior avatar Michael W. Kearney avatar Nathan Eastwood avatar Aurélien Ginolhac avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.