Importing Files

You can download the zip file referenced in this lesson here: https://learndata.net/binge.zip

Model script

# Note: you'll first need to download binge.zip,
# available at https://learndata.net/binge.zip
# Then, edit the following line to match the folder
# where this file is located.
setwd("C:/Users/favero/Downloads")

#install.packages("rio")  # uncomment if rio not installed
library(rio)

unzip("binge.zip")

data_from_xls <- import("binge.xls")

data_from_dta <- import("binge.dta")

data_from_tab <- import("binge.tab", format = "tsv")
?import

# save the dataset "data_from_tab" as an R object file in my working directory
saveRDS(data_from_tab, file = "binge.rds")

Key concepts/syntax:

  1. setwd(): set the “working directory,” which is the default folder on your computer in which Stata will look for files and output files

    setwd("C:/Users/favero/learn data/example files")
  2. unzip(): unzip (extract) a zip file

    unzip("binge.zip")
  3. ?: open a help file for a function or package

    ?read.delim
  4. saveRDS: save a dataset

    saveRDS(data_from_tab, file = "binge.rds")