Import your data

myData <- read.csv("../00_data/boardgames_details.csv")

Pivoting

long to wide form

# Make data set smaller first
data_small <- myData %>%
    
    select(primary, yearpublished, minplayers) %>%
    filter(primary %in% c("Robin Hood", "Chaos"))
#wide form
data_wide <- data_small %>% pivot_wider(names_from = yearpublished, values_from = minplayers)
## Warning: Values from `minplayers` are not uniquely identified; output will contain list-cols.
## * Use `values_fn = list` to suppress this warning.
## * Use `values_fn = {summary_fun}` to summarise duplicates.
## * Use the following dplyr code to identify duplicates.
##   {data} %>%
##     dplyr::group_by(primary, yearpublished) %>%
##     dplyr::summarise(n = dplyr::n(), .groups = "drop") %>%
##     dplyr::filter(n > 1L)

wide to long form

data_long <- data_wide %>% pivot_longer(`2011`:`2019`, names_to = "yearpublished", values_to = "minplayers")
data_long2 <- data_wide %>% pivot_longer(`2011`:`2019`, names_to = "yearpublished", values_to = "minplayers", values_drop_na = TRUE)

Separating and Uniting

Unite two columns

# Unite columns in order to separate since separating the original columns in the data set is NA
data_united <- myData %>%
    
    select(primary, maxplayers, minplayers) %>% 
    filter(primary %in% c("Robin Hood", "Chaos")) %>%
    unite(col = "minandmaxplayers", minplayers:maxplayers, sep = "-", remove = TRUE)

Separate a column

# Separating the conjoined column that was just created
data_separated <- data_united %>%
    
    separate(col = "minandmaxplayers", into = c("minplayers", "maxplayers", sep = "-"))
## Warning: Expected 3 pieces. Missing pieces filled with `NA` in 10 rows [1, 2, 3,
## 4, 5, 6, 7, 8, 9, 10].

Missing Values