[R] Problem with read.spss() and as.data.frame(), or: alternative to subset()?
Dirk Enzmann
dirk.enzmann at jura.uni-hamburg.de
Tue Sep 20 23:44:00 CEST 2005
Trying to select a subset of cases (rows of data) I encountered several
problems:
Firstly, because I did not read the help to read.spss() thoroughly
enough, I treated the data read as a data frame. For example,
dr2000 <- read.spss('myfile.sav')
d <- subset(dr2000,RBINZ99 > 0)
and thus received an error message (Object "RBINZ99" not found), because
dr2000 is not a data.frame but a list (shown by class(dr2000)).
d <- subset(dr2000,dr2000$RBINZ99)
didn' help either, because now d is empty (dim = NULL).
Thus, I tried to use the option "to.data.frame=T" of read.spss():
dr2000 <- read.spss('myfile.sav',to.data.frame=T)
However, now R "crashes" ('R for Windows GUI front-end has found an
error and must be closed') (the error message is in German).
Finally, I tried again using read.spss() without the option
'to.data.frame=T' (as before) and tried to convert dr2000 to a data
frame by using
d <- as.data.frame(dr2000)
However, R crashes again (with the same error message).
Of course, I could use SPSS first and save only the cases with RBINZ99 >
0, but this is not always possible (all users of the data must have SPSS
available and we have to use different selection criteria). Is there
another possibility to solve the problem by using R? I want to select
certain rows (cases) based on the values of one "variable" of dr2000,
but keep all columns (variables) - although dr2000 is not a data frame?
And: R should not crash but rather give a warning.
------------------------
R version 2.1.1 Patched (2005-07-15)
Package Foreign Version 0.8-10
Operating system: Windows XP Professional (5.1 (Build 2600))
CPU: Pentium Model 2 Stepping 9
RAM: 512 MB
*************************************************
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg
Germany
phone: +49-040-42838.7498 (office)
+49-040-42838.4591 (Billon)
fax: +49-040-42838.2344
email: dirk.enzmann at jura.uni-hamburg.de
www:
http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
More information about the R-help
mailing list