HG: A package to share between us

Description Usage Details Working with SPSS files

View source: R/HG.R

Description

This is an overview of the tools in this package

Usage

1
HG()

Details

To update the package:

library(devtools)

install_github("gmonette/HG")

Working with SPSS files

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.


gmonette/HG documentation built on May 17, 2019, 7:25 a.m.