Hello I have a string which contains microseconds, can anyone help on constructing this in to a time object, with the microseconds, that I can take to a ZOO file? Thanks Sean> UK[1,3][1] "17:09:53.824"> UK[1,1][1] "2007-12-11 00:00:00"> mydates <- paste( substr(UK[,1], 1, 10), UK[,3]) > mydates[1][1] "2007-12-11 17:09:53.824"> is(mydates)[1] "character" "vector"> dt1 <- as.POSIXct(strptime(as.character(mydates),"%Y-%m-%d%H:%M:%S",tz="GMT"))> dt1[1][1] "2007-12-11 17:09:53 GMT"> is(dt1)[1] "POSIXt" "oldClass" "POSIXct" "POSIXlt"> >
I don't see microseconds here, only milliseconds. See ?strptime for how to handle this via %OS. On Thu, 8 May 2008, Creighton, Sean wrote:> Hello > > I have a string which contains microseconds, can anyone help on > constructing this in to a time object, with the microseconds, that I can > take to a ZOO file? > > Thanks > Sean > > > >> UK[1,3] > [1] "17:09:53.824" >> UK[1,1] > [1] "2007-12-11 00:00:00" >> mydates <- paste( substr(UK[,1], 1, 10), UK[,3]) >> mydates[1] > [1] "2007-12-11 17:09:53.824" >> is(mydates) > [1] "character" "vector" >> dt1 <- as.POSIXct(strptime(as.character(mydates),"%Y-%m-%d > %H:%M:%S",tz="GMT")) >> dt1[1] > [1] "2007-12-11 17:09:53 GMT"Try> mydates <- "2007-12-11 17:09:53.824" > as.POSIXct(strptime(mydates,"%Y-%m-%d %H:%M:%S",tz="GMT"))[1] "2007-12-11 17:09:53 GMT"> op <- options(digits.secs=3) > as.POSIXct(strptime(mydates,"%Y-%m-%d %H:%M:%OS",tz="GMT"))[1] "2007-12-11 17:09:53.824 GMT"> options(op)See ?Sys.time for a similar example. -- 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
On 8 May 2008 at 14:58, Creighton, Sean wrote:
| Hello
|
| I have a string which contains microseconds, can anyone help on
| constructing this in to a time object, with the microseconds, that I can
| take to a ZOO file?
Easy, just read the docs:
i) you need %0S instead of %S to parse sub-seconds components
ii) you need to tell R to print sub-second components.
edd at ron:~$ r -e 'posixt <- strptime("2007-12-11
17:09:53.824123", "%Y-%m-%d %H:%M:%OS");
options("digits.secs"=6); print(posixt)'
[1] "2007-12-11 17:09:53.824123"
This used littler, but it's the same for R. I set
options("digits.secs"=6)
in my ~/.Rprofile/
Hth, D.
|
| Thanks
| Sean
|
|
|
| > UK[1,3]
| [1] "17:09:53.824"
| > UK[1,1]
| [1] "2007-12-11 00:00:00"
| > mydates <- paste( substr(UK[,1], 1, 10), UK[,3])
| > mydates[1]
| [1] "2007-12-11 17:09:53.824"
| > is(mydates)
| [1] "character" "vector"
| > dt1 <- as.POSIXct(strptime(as.character(mydates),"%Y-%m-%d
| %H:%M:%S",tz="GMT"))
| > dt1[1]
| [1] "2007-12-11 17:09:53 GMT"
| > is(dt1)
| [1] "POSIXt" "oldClass" "POSIXct"
"POSIXlt"
| >
| >
|
| ______________________________________________
| 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.
--
Three out of two people have difficulties with fractions.
Possibly Parallel Threads
- as.Date.character speed improvement suggestion
- selecting columns from a data frame or data table by type, ie, numeric, integer
- fixed effects anova in lme lmer
- selecting columns from a data frame or data table by type, ie, numeric, integer
- Sum data according to date in sequence