This function calls the read_spss
function in the haven package by Hadley Wickham and Evan Miller (2019)
to read an SPSS file.
read.sav(file, use.value.labels = FALSE, use.missings = TRUE, formats = FALSE,
label = TRUE, labels = TRUE, missing = FALSE, widths = FALSE,
as.data.frame = TRUE, check = TRUE)
Returns a data frame or tibble.
a character string indicating the name of the SPSS data file
with or without file extension '.sav', e.g., "My_SPSS_Data.sav"
or "My_SPSS_Data"
.
logical: if TRUE
, variables with value labels are converted into factors.
logical: if TRUE
(default), user-defined missing values are converted into NAs.
logical: if TRUE
, variable formats are shown in an attribute for all variables.
logical: if TRUE
(default), variable labels are shown in an attribute for all variables.
logical: if TRUE
(default), value labels are shown in an attribute for all variables.
logical: if TRUE
, value labels for user-defined missings are shown in an attribute.
for all variables.
logical: if TRUE
, widths are shown in an attribute for all variables.
logical: if TRUE
(default), function returns a regular data frame (default);
if FALSE
function returns a tibble.
logical: if TRUE
, argument specification is checked.
Hadley Wickham and Evan Miller
Hadley Wickham and Evan Miller (2019). haven: Import and Export 'SPSS', 'Stata' and 'SAS' Files. R package version 2.1.1.https://CRAN.R-project.org/package=haven
write.sav
, read.xlsx
, read.mplus
if (FALSE) {
# Read SPSS data
read.sav("SPSS_Data.sav")
read.sav("SPSS_Data")
# Read SPSS data, convert variables with value labels into factors
read.sav("SPSS_Data.sav", use.value.labels = TRUE)
# Read SPSS data, user-defined missing values are not converted into NAs
read.sav("SPSS_Data.sav", use.missing = FALSE)
# Read SPSS data as tibble
read.sav("SPSS_Data.sav", as.data.frame = FALSE)
}
Run the code above in your browser using DataLab