[R] How to convert number (matlab) to date

Joshua Wiley jwiley.psych at gmail.com
Sun Jul 17 06:10:15 CEST 2011


You need to specify the origin:

as.Date(730456, origin = "matlabs origin date")

HTH,

Josh

P.S. Alternately, you may be able to do something like:

## find R's numeric representation of 02-Dec-1999 and use the
difference from Matlabs to offset
MatLabROffset <- 730456 - as.numeric(as.Date("1999-12-02"))
as.Date(730456 - MatLabROffset)


On Sat, Jul 16, 2011 at 8:50 PM, Eduardo M. A. M. Mendes
<emammendes at gmail.com> wrote:
> Hello
>
> I am new to R and I need to convert some dates (numeric format by matlab) to actual dates in R.
>
> For instance,
>
> Matlab -> 730456 -> >> datestr(730456)
>
> ans =
>
> 02-Dec-1999
>
> R -
>
>> library(zoo)
>> as.Date(730456)
> [1] "3969-12-03"
>
> I don't not mind the output format but it needs to be right.
>
>
> Many thanks
>
> Ed
>
> ______________________________________________
> R-help at 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list