Comments (2)
A two column tidy tibble may make sense
# devtools::install_github("tidyverse/dplyr", ref = "across_simpler")
library(dplyr, warn.conflicts = FALSE)
library(tibble)
library(tidyr)
tidy_quantile <- function(x) {
enframe(quantile(x, probs = c(0, .5, 1)), name = "percentile")
}
# ---
# One column
iris %>%
group_by(Species) %>%
summarise(tidy_quantile(Sepal.Length))
#> # A tibble: 9 x 3
#> Species percentile value
#> <fct> <chr> <dbl>
#> 1 setosa 0% 4.3
#> 2 setosa 50% 5
#> 3 setosa 100% 5.8
#> 4 versicolor 0% 4.9
#> 5 versicolor 50% 5.9
#> 6 versicolor 100% 7
#> 7 virginica 0% 4.9
#> 8 virginica 50% 6.5
#> 9 virginica 100% 7.9
# Multiple columns with a return value in the most useful format
iris %>%
pivot_longer(-Species, names_to = "measure") %>%
group_by(Species, measure) %>%
summarise(tidy_quantile(value))
#> # A tibble: 36 x 4
#> # Groups: Species [3]
#> Species measure percentile value
#> <fct> <chr> <chr> <dbl>
#> 1 setosa Petal.Length 0% 1
#> 2 setosa Petal.Length 50% 1.5
#> 3 setosa Petal.Length 100% 1.9
#> 4 setosa Petal.Width 0% 0.1
#> 5 setosa Petal.Width 50% 0.2
#> 6 setosa Petal.Width 100% 0.6
#> 7 setosa Sepal.Length 0% 4.3
#> 8 setosa Sepal.Length 50% 5
#> 9 setosa Sepal.Length 100% 5.8
#> 10 setosa Sepal.Width 0% 2.3
#> # … with 26 more rows
Created on 2019-11-09 by the reprex package (v0.3.0.9000)
from funs.
Could possibly have quantile_wide()
and quantile_long()
? Or have some special data frame subclass so that you could could t()
it?
from funs.
Related Issues (20)
- Should this repo live in tidyverse? HOT 3
- Implement is_distinct()? HOT 2
- A na.rm option for cumany? HOT 1
- na.rm argument in lead and lag? HOT 1
- Common suffixes and prefixes of vectors HOT 2
- Make sure if_else() cross-references to case_when()
- Add `mode` to vector functions
- Consider `case_when()` variant that uses values HOT 4
- `coalesce()` invariants HOT 1
- `set_intersect()`, `set_union()`, `set_diff()`, and `set_equal()`
- coalesce on a single column (typically with summarize) HOT 3
- Make a website
- Move `master` branch to `main` HOT 1
- Consider `case_when()` variant returning ordered factors HOT 3
- case_when() should preserve names HOT 1
- `between()` should recycle `left` and `right` to the size of `x`
- Should near have a digits argument?
- Accessible helper for run length encoded style groups HOT 1
- vec_equal_na is deprecated
- `min()` and `max()` variants with an `empty` argument
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from funs.