Tidy data

Pivoting

long to wide form

table4a_long <- table4a %>%
    
    pivot_longer(cols = c('1999', '2000'),
                 names_to = "year",
                 values_to = "cases")

wide to long form

table4a_long %>%
    
    pivot_wider(names_from = year,
                values_from = cases)
## # A tibble: 3 × 3
##   country     `1999` `2000`
##   <chr>        <dbl>  <dbl>
## 1 Afghanistan    745   2666
## 2 Brazil       37737  80488
## 3 China       212258 213766

Seperating and Uniting

table3_sep <- table3 %>%
    
    separate(col = rate, into = c("cases", "population"))

Unite two columns

table3_sep %>%
    
    unite(col = rate, sep = "/")
## # A tibble: 6 × 1
##   rate                          
##   <chr>                         
## 1 Afghanistan/1999/745/19987071 
## 2 Afghanistan/2000/2666/20595360
## 3 Brazil/1999/37737/172006362   
## 4 Brazil/2000/80488/174504898   
## 5 China/1999/212258/1272915272  
## 6 China/2000/213766/1280428583

Missing Values

Non-Tidy Data