Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Created October 20, 2017 12:45
Show Gist options
  • Save romainfrancois/50a1d17db668c1a7a520b3d30aadabe3 to your computer and use it in GitHub Desktop.
Save romainfrancois/50a1d17db668c1a7a520b3d30aadabe3 to your computer and use it in GitHub Desktop.
library(purrr)
library(dplyr)
row_count <- function(.x, .f){
.f <- as_mapper(.f)
reduce(.x, function(x, y) x + .f(y), .init = 0 )
}
data <- tribble(
~x, ~y, ~z,
1, 2, 3,
0, 2, 3,
0, 0, 0,
4, 5, 5
)
data
data %>%
row_count( ~ . > 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment