Import your data

library(tidyverse)

data <- read_csv("../00_data/Mydata.csv")
## New names:
## Rows: 41152 Columns: 17
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (11): Name, Sex, Event, Equiptment, Age Class, Division, Weight Class KG... dbl
## (5): Age, Bodyweight, Best Sqaut KG, Best Bench KG, Best Deadlifting lgl (1):
## ...17
## ℹ 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.
## • `` -> `...17`
skimr::skim(data)
Data summary
Name data
Number of rows 41152
Number of columns 17
_______________________
Column type frequency:
character 11
logical 1
numeric 5
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
Name 0 1.00 2 36 0 17805 0
Sex 0 1.00 1 1 0 2 0
Event 0 1.00 1 3 0 3 0
Equiptment 0 1.00 3 10 0 3 0
Age Class 2884 0.93 5 6 0 16 0
Division 627 0.98 4 11 0 12 0
Weight Class KG 1 1.00 2 5 0 38 0
Place 0 1.00 1 2 0 34 0
Date 0 1.00 6 8 0 224 0
Federation 0 1.00 3 3 0 1 0
Meet Name 0 1.00 11 54 0 32 0

Variable type: logical

skim_variable n_missing complete_rate mean count
…17 41152 0 NaN :

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
Age 2906 0.93 34.77 14.62 0.50 22.5 31.50 45.0 93.5 ▂▇▅▂▁
Bodyweight 187 1.00 81.15 24.93 37.29 60.0 75.55 97.3 240.0 ▇▆▂▁▁
Best Sqaut KG 13698 0.67 217.55 74.61 -210.00 160.0 215.00 270.0 490.0 ▁▁▇▇▁
Best Bench KG 2462 0.94 144.68 60.03 -160.00 97.5 140.00 185.0 415.0 ▁▁▇▃▁
Best Deadlifting 14028 0.66 221.84 63.72 -215.00 170.0 222.50 270.0 420.0 ▁▁▃▇▂
data_small <- data %>%
    select(Sex, Event, `Best Bench KG`) %>%
    sample_n(10)

Pivoting

long to wide form

?pivot_wider

data_wide <- data_small%>%
    pivot_wider(names_from = Event, values_from = Sex, values_fill = "0")
data_wide
## # A tibble: 9 × 3
##   `Best Bench KG` B     SBD  
##             <dbl> <chr> <chr>
## 1           100   M     F    
## 2            90   F     0    
## 3            65   0     F    
## 4           195   0     M    
## 5           140   0     M    
## 6            82.5 F     0    
## 7           158.  0     M    
## 8           230   0     M    
## 9            NA   0     F

wide to long form

?pivot_longer

data_wide %>%
    pivot_longer(cols = B: SBD)
## # A tibble: 18 × 3
##    `Best Bench KG` name  value
##              <dbl> <chr> <chr>
##  1           100   B     M    
##  2           100   SBD   F    
##  3            90   B     F    
##  4            90   SBD   0    
##  5            65   B     0    
##  6            65   SBD   F    
##  7           195   B     0    
##  8           195   SBD   M    
##  9           140   B     0    
## 10           140   SBD   M    
## 11            82.5 B     F    
## 12            82.5 SBD   0    
## 13           158.  B     0    
## 14           158.  SBD   M    
## 15           230   B     0    
## 16           230   SBD   M    
## 17            NA   B     0    
## 18            NA   SBD   F

Separating and Uniting

Unite two columns

?unite

data_unite <- data_small %>%
    unite(col = "Sex_Event", Event, Sex, sep = "_")

data_unite[10,1] <- "SBD_M_event"
data_unite
## # A tibble: 10 × 2
##    Sex_Event   `Best Bench KG`
##    <chr>                 <dbl>
##  1 B_M                   100  
##  2 B_F                    90  
##  3 SBD_F                  65  
##  4 SBD_M                 195  
##  5 SBD_M                 140  
##  6 B_F                    82.5
##  7 SBD_M                 158. 
##  8 SBD_M                 230  
##  9 SBD_F                  NA  
## 10 SBD_M_event           100

Separate a column

data_unite %>%
    separate(col = Sex_Event, into = c("Sex", "event"), sep = "_")
## Warning: Expected 2 pieces. Additional pieces discarded in 1 rows [10].
## # A tibble: 10 × 3
##    Sex   event `Best Bench KG`
##    <chr> <chr>           <dbl>
##  1 B     M               100  
##  2 B     F                90  
##  3 SBD   F                65  
##  4 SBD   M               195  
##  5 SBD   M               140  
##  6 B     F                82.5
##  7 SBD   M               158. 
##  8 SBD   M               230  
##  9 SBD   F                NA  
## 10 SBD   M               100