> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of arun
> Sent: Friday, December 06, 2013 3:11 PM
> To: R help
> Subject: Re: [R] Wrong date fromat?
> 
> Hi,
> Try
> vec1 <- 10958:10963
>  as.Date(vec1,origin="1960-01-01")
> #[1] "1990-01-01" "1990-01-02" "1990-01-03" "1990-01-04" "1990-01-05"
> #[6] "1990-01-06"
> 
> A.K.
> 
> 
> 
> I have imported a stata data into R and wanted to convert the date.
>  The format went OK, but the output doesn't represent my data. The head
> of the imported data is this one
> 
> > head(df$date)
> [1] 10958 10959 10960 10961 10962 10963
> 
> I tried to convert the date using the zoo package:
> 
> library("zoo")
> df$date<-as.Date(df$date)
> head(df$date)
> 
> > head(df$date)
> [1] "2000-01-02" "2000-01-03" "2000-01-04" "2000-01-05" "2000-01-06"
> "2000-01-07"
> 
> However my date starts with January 1, 1990 and the converted data starts
> from January 2, 2000.
> 
> What have I done wrong?
> 

You need to specify an appropriate value for the origin parameter.  It looks 
like as.Date in the zoo package (which masks the as.Date in base) defaults to 
the Unix epoch value, origin='1970-01-01'.  Your Stata values are based on 
origin='1960-01-01' as your first example specified.

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA
 

______________________________________________
R-help@r-project.org 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 via email to