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:
setwd(): set the “working directory,” which is the default folder on your computer in which Stata will look for files and output filessetwd("C:/Users/favero/learn data/example files")unzip(): unzip (extract) a zip fileunzip("binge.zip")?: open a help file for a function or package?read.delimsaveRDS: save a datasetsaveRDS(data_from_tab, file = "binge.rds")