Question 1

Loading the data and customizing the csv calls.

library(readr)
example_data_bad <- read_delim("https://raw.githubusercontent.com/ati-ozgur/course-r-programming/master/2021/Lab-2021-11-16-ImportData/example-data-bad.csv", delim = "\t", 
    col_types = cols(study_id = col_integer(), 
        patient_id = col_integer(), gender = col_factor(levels = c("F", 
            "M")), age_years = col_integer(), 
        age_months = col_integer(), x = col_skip()), 
    trim_ws = TRUE)
## Warning: One or more parsing issues, see `problems()` for details
head(example_data_bad)
## # A tibble: 6 x 6
##   study_id patient_id gender age_years age_months date_inclusion
##      <int>      <int> <fct>      <int>      <int> <date>        
## 1       NA          4 F              2         27 2011-01-01    
## 2        1         NA F              2         25 2011-01-01    
## 3        1          1 <NA>           2         27 2011-01-01    
## 4        1          2 M             NA         61 2011-01-01    
## 5        1          3 F              9         NA 2011-01-01    
## 6        1          3 M              1         17 2011-01-01

Show data in a table.

tibble::as_tibble(example_data_bad)
## # A tibble: 12 x 6
##    study_id patient_id gender age_years age_months date_inclusion
##       <int>      <int> <fct>      <int>      <int> <date>        
##  1       NA          4 F              2         27 2011-01-01    
##  2        1         NA F              2         25 2011-01-01    
##  3        1          1 <NA>           2         27 2011-01-01    
##  4        1          2 M             NA         61 2011-01-01    
##  5        1          3 F              9         NA 2011-01-01    
##  6        1          3 M              1         17 2011-01-01    
##  7        1          4 M              2         25 2011-01-01    
##  8        2          1 M            200         32 2011-01-01    
##  9        2          2 M              3         24 2011-01-01    
## 10        2          3 F              7         90 2011-01-01    
## 11        2          4 F              1         14 2011-01-01    
## 12        2          5 F              2         25 NA