read.spss reads a file stored by the SPSS save or
export commands.read.spss(file, use.value.labels = TRUE, to.data.frame = FALSE,
max.value.labels = Inf, trim.factor.names = FALSE,
trim_values = TRUE, reencode = NA)use.value.labels = TRUE.use.value.labels = TRUE?NA, means to do so in a UTF-*
locale, only. Alternatively character, specifying an encoding to
assume. If what looks like a Windows codepage was recorded in the SPSS file,
it is attached (as a number) as attribute "codepage" to the
result.
There may be attributes "label.table" and
"variable.labels". Attribute "label.table" is a named
list of value labels with one element per variable, either NULL
or a names character vector.
Attribute "variable.labels" is a named character vector with
names the short variable names and elements the long names.
max.val.labels you can specify that variables with a
large number of distinct values are not converted to factors even if
they have value labels. In addition, variables will not be converted
to factors if there are non-missing values that have no value label.
The value labels are then returned in the "value.labels"
attribute of the variable.
If SPSS variable labels are present, they are returned as the
"variable.labels" attribute of the answer. Fixed length strings (including value labels) are padded on the right
with spaces by SPSS, and so are read that way by R. The default
argument trim_values=TRUE causes trailing spaces to be ignored
when matching to value labels, as examples have been seen where the
strings and the value labels had different amounts of padding. See
the examples for sub for ways to remove trailing spaces
in charcter data.
read.spss("datafile")
## don't convert value labels to factor levels
read.spss("datafile", use.value.labels = FALSE)
## convert value labels to factors for variables with at most
## ten distinct values.
read.spss("datafile", max.val.labels = 10)Run the code above in your browser using DataLab