Created
February 2, 2017 08:25
-
-
Save Keiku/41a48599fa42705ca562b4c3d3eaeee9 to your computer and use it in GitHub Desktop.
Create a summary report.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(tidyr) | |
iris %>% | |
as_data_frame(.) %>% | |
select(matches("Petal")) %>% | |
summarise_all(.funs = c("01:sum" = "sum", | |
"02:min" = "min", | |
"03:q25" = "quantile(., 0.25)", | |
"04:median" = "median", | |
"05:q75" = "quantile(., 0.75)", | |
"06:max" = "max", | |
"07:mean" = "mean", | |
"08:sd" = "sd")) %>% | |
gather(variable, value) %>% | |
separate(variable, c("var", "stat"), sep = "\\_") %>% | |
spread(var, value) | |
# A tibble: 8 × 3 | |
# stat Petal.Length Petal.Width | |
# * <chr> <dbl> <dbl> | |
# 1 01:sum 563.700000 179.9000000 | |
# 2 02:min 1.000000 0.1000000 | |
# 3 03:q25 1.600000 0.3000000 | |
# 4 04:median 4.350000 1.3000000 | |
# 5 05:q75 5.100000 1.8000000 | |
# 6 06:max 6.900000 2.5000000 | |
# 7 07:mean 3.758000 1.1993333 | |
# 8 08:sd 1.765298 0.7622377 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment