[R] spss.read factor reversal

From: Joel Bremson <joel3000_at_gmail.com>
Date: Wed 27 Jul 2005 - 10:04:42 EST


Hi,

I'm having a problem with spss.read reversing my factor input.

Here is the input copied from the spss data editor:

color cost

1 2.30
2 2.40
3 3.00
1 2.10
1 1.00
1 2.00
2 4.00
2 3.20
2 2.33
3 2.44
3 2.55

For color, red=1, blue=2, and green = 3. It's type is 'String' and

>out=read.spss(file)
>out

$COLOR
[1] green blue red green green green blue blue blue red red Levels: red blue green

$COST
[1] 2.30 2.40 3.00 2.10 1.00 2.00 4.00 3.20 2.33 2.44 2.55

attr(,"label.table")
attr(,"label.table")$COLOR
green blue red
3 2 1

attr(,"label.table")$COST
NULL attr(,"variable.labels")
COLOR COST
"color" "cost"

=====EOF===================

Notice that the $COLOR factor data are inverted, looking at the integer output
we see:

> as.integer(out$COLOR)

[1] 3 2 1 3 3 3 2 2 2 1 1

The spss original data looks like this:
1 2 3 1 1 1 2 2 2 3 3

I can easily invert the output mathematically with: q = sapply(m,function(x){ x + 2*(median(unique(m))-x)})

(m is composed of sequential integers starting at one)

,but it seems as though something wrong is happening with read.spss.

Any ideas?

Joel Bremson
Graduate Student
UC Davis

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 27 10:08:43 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:34:02 EST