import(file, format, setclass, …)
file = character string naming a file
format = (optional) character string of file format; e.g., ","
for comma-separated values
setclass = (optional) character vector specifying one or more classes to set on the import. Default is "data.frame"
. We would probably prefer "tbl_df"
for a tibble
convert()
Another really useful feature is convert()
, which just takes a file of one type and converts it to another
Say your advisor uses SPSS 😐, but their colleague uses Stata 😐, and you use R
😎
Just run one line of code!
convert(in_file, out_file, …)
in_file = character string naming an input file
out_file = character string naming an output file
convert(here(“data”, ecls-k_samp.sav), here(“data”, ecls-k_samp.txt))
Maintaining data “labels”
Question: How many of you or your colleagues use SPSS or Stata?
and/or: How many of you use Qualtrics?
In SPSS, Stata, & Qualtrics numeric data are often encoded with labels
For SAS, Stata, and SPSS files use {haven}
{haven}
allow you to transform the data into the character/factor version
{haven}
store metadata from rich file formats (SPSS, Stata, etc.) in variable-level attributes in a consistent form regardless of file type or underlying import function
rio::characterize()
converts a single variable or all variables in the data that have label attributes into character vectors
rio::factorize()
does the same but returns factor variables
This is very important for several of your homeworks!