[R] matlab serial date to r

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jun 25 18:03:31 CEST 2014


See ?as.Date.

I am guessing these are days and fractional days.  Try

x <- 7.356000000813091e5
as.POSIXct((x - 719529)*86400, origin = "1970-01-01")




On 25/06/2014 14:56, Christoph Schlächter wrote:
> Hi,
>
> I have a matlab variable as serial date (class double) in the form
> 'dd-mmm-yyyy HH:MM:SS'.
>
> format long
> disp( tx(40:60,1) )
>
> 1.0e+05 *
>
>     7.356000000813091
>     7.356000000956856
>     7.356000001305921
>     7.356000001654985
>     7.356000002004049
>     7.356000002353113
>     7.356000002702178
>     7.356000003397179
>     7.356000004092182
>     7.356000004787183
>     7.356000005482185
>     7.356000006177187
>     7.356000006940080
>     7.356000007702975
>     7.356000008465869
>     7.356000009228763
>     7.356000009991657
>     7.356000010754551
>     7.356000011517445
>     7.356000012280339
>     7.356000013085329
>
> It should be the same as
>
> datestr( tx(40:60,1), 0)
>
> 01-Jan-2014 00:00:07
> 01-Jan-2014 00:00:08
> 01-Jan-2014 00:00:11
> 01-Jan-2014 00:00:14
> 01-Jan-2014 00:00:17
> 01-Jan-2014 00:00:20
> 01-Jan-2014 00:00:23
> 01-Jan-2014 00:00:29
> 01-Jan-2014 00:00:35
> 01-Jan-2014 00:00:41
> 01-Jan-2014 00:00:47
> 01-Jan-2014 00:00:53
> 01-Jan-2014 00:00:59
> 01-Jan-2014 00:01:06
> 01-Jan-2014 00:01:13
> 01-Jan-2014 00:01:19
> 01-Jan-2014 00:01:26
> 01-Jan-2014 00:01:32
> 01-Jan-2014 00:01:39
> 01-Jan-2014 00:01:46
> 01-Jan-2014 00:01:53
>
> I can easily convert it with Matlab but then I will obtain a character
> format which is useless. I can also make use of cellstr(datestr(tx(:,1),
> 0)) but then I can't save it in ASCII file.
>
> The origin of the Matlab format is supposed to be "0000-00-00". This is the
> only origin which results in "2014-01-01" which is my actual start date.
>
> Can somebody please tell me how I can simply convert serial datetime to
> datetime in R.
>
> Thanks in advance.
>
> All the best,
>
> Christoph
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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



More information about the R-help mailing list