Opening SPSS Portable files in R

R is a free software environment designed for statistical computing and graphics. This guide describes how a quantitative data file downloaded from FSD’s Aila Data Service is opened in R. The paths used in this guide (e.g. 'D:/R_lib') may need to be changed to match the setup on your computer.

In order to open portable files (*.por), you need an R package memisc, which can be installed, for instance, from the RGui menu Packages → Install Package(s) or by entering the following command on the command line of R: install.packages('memisc') .

After installation, the package is loaded into the R session by using the command library('memisc'). If desired, the installation directory can also be manually chosen by invoking the command

install.packages('memisc', lib='D:/R_lib') ,

and loaded for use with the command

library('memisc', lib.loc='D:/R_lib') .

After loading memisc, SPSS Portable file can be opened by entering the command

ds <-'D:/data.por')) .

This command creates an object ds, whose type is data set. The type of individual variables in the data is item, which contains both the values and value labels of a variable. Numerical values corresponding to value labels can be checked with the command codebook(ds$$q1), which displays the frequencies of variable q1. Similarly, the command codebook(ds) displays the frequency tables of all variables.

Numerical values can be saved as a separate variable by using the command

q1 <- as.numeric(ds$$q1) .

The data can also be transformed into a more commonly used type data frame with the command

df <- .

However, when this is done, the variables of the item type are transformed into the type factor. The value labels are retained but original numerical values are replaced by index numbers 1, 2, ..., n.