Skip to content

Commit

Permalink
updated to dplyr 1.0 arcade package
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rodrigues committed Nov 15, 2020
1 parent fa5a6bd commit 855efd4
Show file tree
Hide file tree
Showing 15 changed files with 2,225 additions and 2,170 deletions.
63 changes: 33 additions & 30 deletions 09-package_development.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -399,25 +399,27 @@ script where `describe_numeric()` is might be a good idea, so let's do just that
#' }
describe_numeric <- function(df, ...){
if (nargs() > 1) df <- select(df, ...)
if (nargs() > 1) df <- select(df, ...)
df %>%
select_if(is.numeric) %>%
gather(variable, value) %>%
group_by(variable) %>%
summarise_all(list(mean = ~mean(., na.rm = TRUE),
sd = ~sd(., na.rm = TRUE),
nobs = ~length(.),
min = ~min(., na.rm = TRUE),
max = ~max(., na.rm = TRUE),
q05 = ~quantile(., 0.05, na.rm = TRUE),
q25 = ~quantile(., 0.25, na.rm = TRUE),
mode = ~as.character(brotools::sample_mode(.), na.rm = TRUE),
median = ~quantile(., 0.5, na.rm = TRUE),
q75 = ~quantile(., 0.75, na.rm = TRUE),
q95 = ~quantile(., 0.95, na.rm = TRUE),
n_missing = ~sum(is.na(.)))) %>%
mutate(type = "Numeric")
df %>%
select(is.numeric) %>%
pivot_longer(cols = everything(),
names_to = "variable", values_to = "value") %>%
group_by(variable) %>%
summarise(across(everything(),
tibble::lst(mean = ~mean(., na.rm = TRUE),
sd = ~sd(., na.rm = TRUE),
nobs = ~length(.),
min = ~min(., na.rm = TRUE),
max = ~max(., na.rm = TRUE),
q05 = ~quantile(., 0.05, na.rm = TRUE),
q25 = ~quantile(., 0.25, na.rm = TRUE),
mode = ~as.character(brotools::sample_mode(.), na.rm = TRUE),
median = ~quantile(., 0.5, na.rm = TRUE),
q75 = ~quantile(., 0.75, na.rm = TRUE),
q95 = ~quantile(., 0.95, na.rm = TRUE),
n_missing = ~sum(is.na(.))))) %>%
mutate(type = "Numeric")
}
#' Compute descriptive statistics for the character or factor columns of a data frame.
Expand All @@ -426,30 +428,31 @@ describe_numeric <- function(df, ...){
#' @import dplyr
#' @importFrom tidyr gather
describe_character_or_factors <- function(df, type){
df %>%
gather(variable, value) %>%
group_by(variable) %>%
summarise_all(funs(mode = brotools::sample_mode(value, na.rm = TRUE),
nobs = length(value),
n_missing = sum(is.na(value)),
n_unique = length(unique(value)))) %>%
mutate(type = type)
df %>%
pivot_longer(cols = everything(),
names_to = "variable", values_to = "value") %>%
group_by(variable) %>%
summarise(across(everything(),
funs(mode = brotools::sample_mode(value, na.rm = TRUE),
nobs = length(value),
n_missing = sum(is.na(value)),
n_unique = length(unique(value))))) %>%
mutate(type = type)
}
#' Compute descriptive statistics for the character columns of a data frame.
#' @param df The data frame to summarise.
#' @return A data frame with a description of the character columns.
#' @import dplyr
#' @importFrom tidyr gather
#' @export
#' @examples
#' \dontrun{
#' describe(dataset)
#' }
describe_character <- function(df){
df %>%
select_if(is.character) %>%
describe_character_or_factors(type = "Character")
df %>%
select(where(is.character)) %>%
describe_character_or_factors(type = "Character")
}
```

Expand Down
567 changes: 292 additions & 275 deletions docs/defining-your-own-functions.html

Large diffs are not rendered by default.

1,449 changes: 731 additions & 718 deletions docs/descriptive-statistics-and-data-manipulation.html

Large diffs are not rendered by default.

842 changes: 421 additions & 421 deletions docs/functional-programming.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/further-topics.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-11-07" />
<meta name="date" content="2020-11-10" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-to-know-rstudio.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-11-07" />
<meta name="date" content="2020-11-10" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
458 changes: 229 additions & 229 deletions docs/graphs.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-11-07" />
<meta name="date" content="2020-11-10" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down Expand Up @@ -422,7 +422,7 @@ <h1>
<div id="header">
<h1 class="title">Modern R with the tidyverse</h1>
<p class="author"><em>Bruno Rodrigues</em></p>
<p class="date"><em>2020-11-07</em></p>
<p class="date"><em>2020-11-10</em></p>
</div>
<div id="preface" class="section level1 unnumbered" number="">
<h1>Preface</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-11-07" />
<meta name="date" content="2020-11-10" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
Loading

0 comments on commit 855efd4

Please sign in to comment.