[R] read.spss and time/date information

Chuck Cleland ccleland at optonline.net
Wed Mar 3 17:37:19 CET 2004


Torsten Hothorn wrote:
> I could not find any information on how `read.spss' deals with date
> information. As an example, I created a file containing two variables,
> one numeric (values = (1, 2)) and one of type "Datum" in SPSS (german
> version with values "11.02.2003" and "03.04.1999" and I get in R:
> 
> SPSSfile = url("http://www.imbe.med.uni-erlangen.de/~hothorn/dates.sav", "rb")
> SPSSdata = readBin(SPSSfile, "numeric", n = 10000)
> writeBin(SPSSdata, con = "dummy.sav")
> library(foreign)
> read.spss("dummy.sav")
> 
> $DUMMY
> [1] 1 2
> 
> $DATE
> [1] 13264300800 13142476800
> 
> attr(,"label.table")
> attr(,"label.table")$DUMMY
> NULL
> 
> attr(,"label.table")$DATE
> NULL
> 
> 
> Could anyone give me a a hint how I can convert 13264300800 to 2003/02/11
> again, please?

   Date variables in SPSS contain the number of seconds since 
October 14, 1582.  I think you could do something like this to 
convert:

 > ISOdate(1582, 10, 14) + c(13264300800, 13142476800)
[1] "2003-02-11 07:00:00 Eastern Standard Time"
[2] "1999-04-03 07:00:00 Eastern Standard Time"

hope this helps,

Chuck Cleland

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list