Description Usage Details Working with SPSS files
This is an overview of the tools in this package
1 | HG()
|
To update the package:
library(devtools)
install_github("gmonette/HG")
Hadley Wickham's haven
package makes it easy to read and write SPSS
'sav' files but there are problems integrating his package with R functions
that manipulate packages, such as merge
.
These functions facilitate manipulating SPSS files in R so they can be rewritten back to SPSS.
The main haven
functions are read_sav
and
write_sav
.
If a variable in the SPSS file has a variable label then
read_sav
stores the label in the'label' attribute of the
corresponding R variable. The class of the variable is not
affected by the presence of a variable label. Thus variable labels
can be read and and set with:
attr(data$Gender,"label")
attr(data$Gender,"label") <- "Gender of respondent"
The varlab
function provides an alternative way of doing this:
varlab(data$Gender)
varlab(data$Gender) <- "Gender of respondent"
You can read all the variable labels for a whole data frame with:
vlabs <- varlabels(data)
and later restore those variable labels with
varlabels(data) <- vlabs
If the SPSS variable has value labels then these labels
are stored in the 'labels' (note the plural) attribute of the
R variable and its class is set to labelled
.
(e.g.attr(dd$Sex,'label')
) and the value labels are
stored in the 'labels' attribute (e.g.attr(dd$Sex,'labels')
).
Variables that have value labels in data sets created by read_sav
belong to haven
's labelled
class.
Many manipulations in R will lose the variable labels. These need to be restored before writing the file back to SPSS.
Current and planned functions to work with 'haven':
toR
: Transform 'labelled' variables to factors.
varlabels
: Read and restore variable labels for a data frame.
varlab
: Read and modify value label for individual variable.
merge_check
: Check compatibility of variable classes for merging.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.