Sales

Mine Çetinkaya-Rundel

library(tidyverse)
library(readxl)
Sales <- read_excel("data-raw/sales.xlsx", skip = 3, col_names = c("id","n"))
Sales %>%
  mutate(
    is_brand_name = str_detect(id, "brand"),
    brand = if_else(is_brand_name, id, NULL)
  ) %>%
  fill(brand) %>%
  filter(!is_brand_name) %>%
  select(brand, id, n)
## # A tibble: 9 × 3
##   brand id      n    
##   <chr> <chr>   <chr>
## 1 <NA>  Brand 1 n    
## 2 <NA>  1234    8    
## 3 <NA>  8721    2    
## 4 <NA>  1822    3    
## 5 <NA>  Brand 2 n    
## 6 <NA>  3333    1    
## 7 <NA>  2156    3    
## 8 <NA>  3987    6    
## 9 <NA>  3216    5