class: title-slide <br> <br> .right-panel[ # Importing Data in R ## Mine Dogucu ] --- ## Importing .csv Data `.csv` stands for comma separated values ``` r readr::read_csv("dataset.csv") ``` --- ## Importing Excel Data ``` r readxl::read_excel("dataset.xlsx") ``` --- ## Importing Excel Data ``` r readxl::read_excel("dataset.xlsx", sheet = 2) ``` --- ## Importing SAS, SPSS, Stata Data ``` r library(haven) # SAS read_sas("dataset.sas7bdat") # SPSS read_sav("dataset.sav") # Stata read_dta("dataset.dta") ``` --- ## Writing data files ``` r write_csv(data_frame, "dataset.csv") write_xls(data_frame, "dataset.xlsx") ``` Similar code pattern holds true for other data formats. --- ## Practice - Importing Download the HIV Antibody Test from the [CDC website](https://wwwn.cdc.gov/nchs/nhanes/search/datapage.aspx?Component=Laboratory&CycleBeginYear=2017). Import it into R. Note that this file has an `.XPT` extension which we have not seen before. Let's see if we can open it using one of the packages we have already seen. --- ## Practice - Packages Refer to your notes or do some investigation (i.e. on CRAN, R Help documentation) to identify a package or function you might use to complete these typical data engineering tasks (Just *find* the tool, don't worry about writing code!): - Change the name of the variable female to gender. - Recode level 0 as `"male"` and level 1 as `"female"`. - Count these levels. - Write the summary table with counts into a `.csv` file.