Import your data
# csv file
mydata <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-07-01/weekly_gas_prices.csv')
## Rows: 22360 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): fuel, grade, formulation
## dbl (1): price
## date (1): date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Separating and Uniting
Separate a column
mydata_sep <- mydata %>%
separate(col = formulation, into = c("all", "na"))
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 19672 rows [1, 2, 3, 4,
## 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
Unite two columns
mydata_sep %>%
unite(col = "formulation", all:na, sep = "/")
## # A tibble: 22,360 × 5
## date fuel grade formulation price
## <date> <chr> <chr> <chr> <dbl>
## 1 1990-08-20 gasoline regular all/NA 1.19
## 2 1990-08-20 gasoline regular conventional/NA 1.19
## 3 1990-08-27 gasoline regular all/NA 1.25
## 4 1990-08-27 gasoline regular conventional/NA 1.25
## 5 1990-09-03 gasoline regular all/NA 1.24
## 6 1990-09-03 gasoline regular conventional/NA 1.24
## 7 1990-09-10 gasoline regular all/NA 1.25
## 8 1990-09-10 gasoline regular conventional/NA 1.25
## 9 1990-09-17 gasoline regular all/NA 1.27
## 10 1990-09-17 gasoline regular conventional/NA 1.27
## # ℹ 22,350 more rows
Missing Values
mydata %>%
filter(!is.na(price))
## # A tibble: 22,360 × 5
## date fuel grade formulation price
## <date> <chr> <chr> <chr> <dbl>
## 1 1990-08-20 gasoline regular all 1.19
## 2 1990-08-20 gasoline regular conventional 1.19
## 3 1990-08-27 gasoline regular all 1.25
## 4 1990-08-27 gasoline regular conventional 1.25
## 5 1990-09-03 gasoline regular all 1.24
## 6 1990-09-03 gasoline regular conventional 1.24
## 7 1990-09-10 gasoline regular all 1.25
## 8 1990-09-10 gasoline regular conventional 1.25
## 9 1990-09-17 gasoline regular all 1.27
## 10 1990-09-17 gasoline regular conventional 1.27
## # ℹ 22,350 more rows