[R] Getting dates in an SPSS file in right format.
Frank E Harrell Jr
f.harrell at Vanderbilt.Edu
Tue May 18 20:58:31 CEST 2010
On 05/18/2010 11:52 AM, Chuck Cleland wrote:
> On 5/18/2010 12:38 PM, Praveen Surendran wrote:
>> Dear all,
>>
>>
>>
>> I am trying to read an SPSS file into a data frame in R using method
>> read.spss(),
>>
>> sample<- read.spss(file.name,to.data.frame=TRUE)
>>
>>
>>
>> But dates in the data.frame 'sample' are coming as integers and not in the
>> actual date format given in the SPSS file.
>>
>> Appreciate if anyone can help me to solve this problem.
>
> Date variables in SPSS contain the number of seconds since
> October 14, 1582. You might try something like this:
>
> sample$MYDATE<- as.Date(as.POSIXct(sample$MYDATE, origin="1582-10-14",
> tz="GMT"))
>
>> Kind Regards,
>>
>>
>>
>> Praveen Surendran
>>
>> 2G, Complex and Adaptive Systems Laboratory (UCD CASL)
>>
>> School of Medicine and Medical Sciences
>>
>> University College Dublin
>>
>> Belfield, Dublin 4
>>
>> Ireland.
>>
>>
>>
>> Office : +353-(0)1716 5334
>>
>> Mobile : +353-(0)8793 13071
>>
The spss.get function in the Hmisc package handles SPSS dates.
Frank
--
Frank E Harrell Jr Professor and Chairman School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list