How to convert SPSS date data to dates?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to convert SPSS date data to dates?

Jonathan Williams-2
Dear R Helpers,

I have imported an SPSS file that contains date data.
The data appear in R in a numeric format, as follows:

10485849600 10477641600 10561104000 10562745600 etc.

I'd be extremely grateful if someone could tell me
how to make these numbers into comprehensible dates!

Thanks,

Jonathan Williams

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to convert SPSS date data to dates?

Peter Dalgaard
"Jonathan Williams" <[hidden email]> writes:

> Dear R Helpers,
>
> I have imported an SPSS file that contains date data.
> The data appear in R in a numeric format, as follows:
>
> 10485849600 10477641600 10561104000 10562745600 etc.
>
> I'd be extremely grateful if someone could tell me
> how to make these numbers into comprehensible dates!

> c(10485849600,10477641600,10561104000,10562745600)+ISOdate(1582,10,14)
[1] "1915-01-26 13:00:00 CET" "1914-10-23 13:00:00 CET"
[3] "1917-06-15 13:00:00 CET" "1917-07-04 13:00:00 CET"

Does this look right? (If you don't want the times, use as.Date).

BTW: There's a strange asymmetry:

> ISOdate(1582,10,14)+
> c(10485849600,10477641600,10561104000,10562745600)
[1] "1915-01-26 12:00:00 GMT" "1914-10-23 12:00:00 GMT"
[3] "1917-06-15 12:00:00 GMT" "1917-07-04 12:00:00 GMT"

(have we seen this before?).

--
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to convert SPSS date data to dates?

Chuck Cleland
In reply to this post by Jonathan Williams-2
Here is one way:

library(chron)

as.chron(ISOdate(1582, 10, 14) + mydata$SPSSDATE)

Jonathan Williams wrote:

> Dear R Helpers,
>
> I have imported an SPSS file that contains date data.
> The data appear in R in a numeric format, as follows:
>
> 10485849600 10477641600 10561104000 10562745600 etc.
>
> I'd be extremely grateful if someone could tell me
> how to make these numbers into comprehensible dates!
>
> Thanks,
>
> Jonathan Williams
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to convert SPSS date data to dates?

Prof Brian Ripley
In reply to this post by Peter Dalgaard
On Thu, 16 Feb 2006, Peter Dalgaard wrote:

> "Jonathan Williams" <[hidden email]> writes:
>
>> Dear R Helpers,
>>
>> I have imported an SPSS file that contains date data.
>> The data appear in R in a numeric format, as follows:
>>
>> 10485849600 10477641600 10561104000 10562745600 etc.
>>
>> I'd be extremely grateful if someone could tell me
>> how to make these numbers into comprehensible dates!
>
>> c(10485849600,10477641600,10561104000,10562745600)+ISOdate(1582,10,14)
> [1] "1915-01-26 13:00:00 CET" "1914-10-23 13:00:00 CET"
> [3] "1917-06-15 13:00:00 CET" "1917-07-04 13:00:00 CET"
>
> Does this look right? (If you don't want the times, use as.Date).
>
> BTW: There's a strange asymmetry:
>
>> ISOdate(1582,10,14)+
>> c(10485849600,10477641600,10561104000,10562745600)
> [1] "1915-01-26 12:00:00 GMT" "1914-10-23 12:00:00 GMT"
> [3] "1917-06-15 12:00:00 GMT" "1917-07-04 12:00:00 GMT"
>
> (have we seen this before?).

Yes, and the second is correct.  Timezones are taken from the lhs in
+.POSIXt.  (That could probably now safely be changed.)

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to convert SPSS date data to dates?

Gabor Grothendieck
In reply to this post by Jonathan Williams-2
spss.get in package Hmisc can handle SPSS dates automatically.
This and additional discussion on SPSS dates is available
in the Help Desk article in R News 4/1.

On 2/16/06, Jonathan Williams
<[hidden email]> wrote:

> Dear R Helpers,
>
> I have imported an SPSS file that contains date data.
> The data appear in R in a numeric format, as follows:
>
> 10485849600 10477641600 10561104000 10562745600 etc.
>
> I'd be extremely grateful if someone could tell me
> how to make these numbers into comprehensible dates!
>
> Thanks,
>
> Jonathan Williams
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html