![]() # 8 Bantry General… 704 Outreach Dermatolo… General Ref… # 7 Bantry General… 704 Medicine for the E… General Ref… ![]() # 6 Bantry General… 704 General Surgery General Ref… # 5 Bantry General… 704 General Medicine General Ref… # 4 Bantry General… 704 Gastroenterology General Ref… # 3 AMNCH 1049 Paediatric General… General Ref… # 2 AMNCH 1049 Paediatric Gastroe… General Ref… # 1 AMNCH 1049 Paediatric ENT General Ref… Map_dfr(read_csv, col_types = cols("Month_Year" = col_date(format = "%b-%y"))) # A tibble: 12,278 x 6 We can modify the arguments of read_csv() inside the call to map_dfr(), which sets the arguments for each CSV import. Notice that the Month_Year column was imported as a character instead of a date-time. with 12,268 more rows, and 1 more variable: TotalReferrals # 10 Aug-15 Bantry General… 704 Outreach Surgical General Ref… # 9 Aug-15 Bantry General… 704 Outreach Orthopaed… General Ref… # 8 Aug-15 Bantry General… 704 Outreach Dermatolo… General Ref… # 7 Aug-15 Bantry General… 704 Medicine for the E… General Ref… # 6 Aug-15 Bantry General… 704 General Surgery General Ref… # 5 Aug-15 Bantry General… 704 General Medicine General Ref… # 4 Aug-15 Bantry General… 704 Gastroenterology General Ref… # 3 Aug-15 AMNCH 1049 Paediatric General… General Ref… # 2 Aug-15 AMNCH 1049 Paediatric Gastroe… General Ref… # 1 Aug-15 AMNCH 1049 Paediatric ENT General Ref… # Month_Year Hospital_Name Hospital_ID Hospital_Department ReferralType (It’s the same as calling map() %>% bind_rows().) csv_files %>% The additional _dfr() tells purrr to return a data frame ( df) by row-binding each element together ( r). To read all of the files in the directory, we map read_csv() onto the list of files, using purrr::map().īut knowing that each list element will be a tibble (or ame) and that each data frame has the same columns, we can use purrr’s typed functions to return a single data frame containing each of the imported CSV files using purrr::map_dfr(). csv_files <- fs::dir_ls(data_dir, regexp = "\\.csv$")Ĭsv_files # ie-general-referrals-by-hospital/general-referrals-by-hospital-department-2015.csv Notice that there is an additional README.txt file that we don’t want to import, so we limit our directory listing to just the CSV files, i.e. the files that end with. # ie-general-referrals-by-hospital/general-referrals-by-hospital-department-2018.csv # ie-general-referrals-by-hospital/general-referrals-by-hospital-department-2017.csv # ie-general-referrals-by-hospital/general-referrals-by-hospital-department-2016.csv # ie-general-referrals-by-hospital/general-referrals-by-hospital-department-2015.csv fs::dir_ls(data_dir) # ie-general-referrals-by-hospital/README.txt We can then list the CSV files using fs::dir_ls(). ![]() data_dir <- "ie-general-referrals-by-hospital" Once we’ve extracted the zip file or downloaded the CSV files a single folder, we store the location of the unzipped folder in data_dir. We’ve collected the data for you, which you can download as a zipfile here, or you can download the original CSV files from. To make the example more concrete, we’ll use a dataset provided by the Government of Ireland showing the yearly number of e-referrals per hospital department, where the data from each year reside in individual CSV files. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |