Getting dates in an SPSS file in right format.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting dates in an SPSS file in right format.

Praveen Surendran-2
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.

 

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

 


        [[alternative HTML version deleted]]

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Getting dates in an SPSS file in right format.

Chuck Cleland
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
>
>  
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained, reproducible code.

--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Getting dates in an SPSS file in right format.

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

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Frank Harrell
Department of Biostatistics, Vanderbilt University