inst/examples/tbl_pivot_longer_examples.R

library(tidyverse)
library(asbtools)
who %>% tbl_pivot_longer(
  cols = new_sp_m014:newrel_f65,
  names_to = c("diagnosis", "gender", "age"),
  names_pattern = "new_?(.*)_(.)(.*)",
  values_to = "count"
)

long_cols <- billboard %>% select(starts_with("wk")) %>% names()

billboard %>% tbl_pivot_longer(
  long_columns = long_cols,
  names_to = "week",
  names_prefix = "wk",
  values_to = "rank",
  values_drop_na = TRUE
)

relig_income %>%
  tbl_pivot_longer(names_to = "income", values_to = "count")
abresler/asbtools documentation built on July 28, 2022, 11:04 p.m.