In SPSS compatible datafiles, every variable has a property called
'Measure'. This attribute can be observed as the last column in 'variable
view mode' when the dataset is opened in e.g. GNU PSPP. The property is not
very important, but is used by many researchers to distinguish between
'Ordinal' and 'Nominal' variables; respectively ordered and unordered
factors in R.

The measure property does not seem to be extracted by the foreign::read.spss
function. It would be nice if there would be a way to read this information,
and add is as an attribute to every variable.

A very useful feature (at least for me :-) would be to include an option in
read.spss that variables which are currently converted to an R factor, will
be converted to an ordered.factor when Measure equals 'Ordinal'. Or in
pseudocode:

After reading in the spss dataset and converting it to a data.frame:
for var in data.frame:
    if ( class ( var ) == "factor" && Measure == "Ordinal" ) {
        class ( var ) <- c( "ordered", "factor" )
    }

Here a datafile to play with:

download.file("http://www.stat.ucla.edu/~jeroen/files/1991GS.sav";,
"1991GS.sav");
mydata <- read.spss("1991GS.sav", to.data.frame=T);
sapply(mydata, is.ordered);

Thanks.

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to