[R] matlab serial date to r

arun smartpink111 at yahoo.com
Wed Jun 25 19:01:29 CEST 2014


Hi,
May be this helps:

dat <- read.table(text="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",sep="",header=F, colClasses="character")
library(chron)
t1 <- chron(1.0e+05 *as.numeric(dat[,1])) -719529
format(as.POSIXct(paste(as.Date(dates(t1)), times(t1)%%1)),"%m-%b-%Y %H:%M:%S")


A.K.



On Wednesday, June 25, 2014 10:00 AM, Christoph Schlächter <christoph.schlaechter at gmail.com> 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.



More information about the R-help mailing list