library(vroom) library(here) library(dplyr) library(magrittr) library(fs) library(tidyverse) options(dplyr.summarise.inform = FALSE) devtools::load_all()
This s technique for taking a dataset. Splitting it up for something (i.e. male/female). Doing something to it, and bringing it back.
mmash %>% group_by(day) %>% summarise(across( c(age, weight, height), list(mean = mean, sd = sd, max = max, min = min), na.rm = T ))
mmash %>% select(-samples) %>% pivot_longer(c(-user_id, -day, -gender))
Use pivot_longer() after the group_by() and summarise() we did previously:
# Data mmash %>% group_by(day) %>% summarise(across( c(age, weight), list(mean = mean, sd = sd), na.rm = TRUE )) # Pivot mmash %>% group_by(day) %>% summarise(across( c(age, weight), list(mean = mean, sd = sd), na.rm = TRUE )) %>% pivot_longer(ends_with(c("mean", "sd")), names_to = c("names", ".value"), names_sep = "_")
We can actually utilize pivot_longer function of naming stuff, to enable us to more easially use pivot_wider.
mmash %>% group_by(day) %>% summarise(across( c(age, weight), list(mean = mean, sd = sd), na.rm = TRUE )) %>% pivot_longer(ends_with(c("mean", "sd")), names_to = c("names", "summary_statistic"), names_sep = "_") %>% pivot_wider(names_from = summary_statistic, values_from = value)
Do it using a funciton
tidy_summarize_by_day(mmash, c("age", "weight")) tidy_summarize_by_day(mmash, c(age, weight))
Non-standard evaluation is the thing with {{}}
tidy_summarize_by_day(mmash, c(age, weight)) %>% knitr::kable(caption = "Nice table")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.