Hi, I cannot figure out how to change the index format when displaying POSIXct objects. Would like the xts index to display as %H:%M:%OS3 when doing viewing the xts object. Think I am missing the obvious. Cheers, Chris -- View this message in context: http://r.789695.n4.nabble.com/xts-POSIXct-index-format-tp3336136p3336136.html Sent from the R help mailing list archive at Nabble.com.
On Mar 4, 2011, at 6:57 PM, rivercode wrote:> Hi, > > I cannot figure out how to change the index format when displaying > POSIXct > objects. > > Would like the xts index to display as %H:%M:%OS3 when doing viewing > the xts > object.If you are not satisfied with the default format, you have (at least) two options: a) specify a format when you call print b) redefine the default. The default is determined within the print.xts function by a call to indexFormat > indexFormat function (x) { attr(x, ".indexFORMAT") } <environment: namespace:xts> So it looks as though you would need to either replace indexFormat or change the attribute of your xts objects. Read further at: ?indexFormat> > Think I am missing the obvious.If you mean looking at the source code, then perhaps you were missing the obvious, or at least merely readily accessible. I don't actually see the option of including a format string in the attribute, so modifying the function may be needed. -- David Winsemius, MD Heritage Laboratories West Hartford, CT
Hi Chris, Perhaps something like this? require(xts) ds <- options(digits.secs=6) # so we can see sub-seconds x <- xts(1:10, as.POSIXct("2011-01-21") + c(1,1,1,2:8)/1e3) x indexFormat(x) <- "%H:%M:%OS3" x Hope that helps, -- Joshua Ulrich ?| ?FOSS Trading: www.fosstrading.com On Fri, Mar 4, 2011 at 5:57 PM, rivercode <aquanyc at gmail.com> wrote:> Hi, > > I cannot figure out how to change the index format when displaying POSIXct > objects. > > Would like the xts index to display as %H:%M:%OS3 when doing viewing the xts > object. > > Think I am missing the obvious. > > Cheers, > Chris > > -- > View this message in context: http://r.789695.n4.nabble.com/xts-POSIXct-index-format-tp3336136p3336136.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
Thank you for your help. indexFormat(x) solved the problem nicely.> head(a)2011-03-04 09:30:00.0 22.10 2011-03-04 09:30:00.1 22.09 2011-03-04 09:30:00.2 22.10 2011-03-04 09:30:00.3 22.09 2011-03-04 09:30:00.4 22.10 2011-03-04 09:30:00.5 22.09> indexFormat(a) <- "%H:%M:%OS3" > head(a)09:30:00.000 22.10 09:30:00.100 22.09 09:30:00.200 22.10 09:30:00.300 22.09 09:30:00.400 22.10 09:30:00.500 22.09 -- View this message in context: http://r.789695.n4.nabble.com/xts-POSIXct-index-format-tp3336136p3337167.html Sent from the R help mailing list archive at Nabble.com.
On Mar 5, 2011, at 11:28 AM, Joshua Ulrich wrote:> Hi Chris, > > Perhaps something like this? > > require(xts) > ds <- options(digits.secs=6) # so we can see sub-seconds > x <- xts(1:10, as.POSIXct("2011-01-21") + c(1,1,1,2:8)/1e3) > x > indexFormat(x) <- "%H:%M:%OS3" > x >Joshua; Does your reading of help(indexFormat) lead you to that suggestion? When I read it I thought that indexFormat would only accept onoe of " Date, POSIXct, chron,yearmon, yearqtr or timeDate." Those were the formats mentioned in the immediately preceding paragraph. I went to the help page hoping I would be told I could use format strings but left it thinking that I could only specify format classes. -- David> Hope that helps, > -- > Joshua Ulrich | FOSS Trading: www.fosstrading.com > > > > On Fri, Mar 4, 2011 at 5:57 PM, rivercode <aquanyc at gmail.com> wrote: >> Hi, >> >> I cannot figure out how to change the index format when displaying >> POSIXct >> objects. >> >> Would like the xts index to display as %H:%M:%OS3 when doing >> viewing the xts >> object. >> >> Think I am missing the obvious. >> >> Cheers, >> Chris >> >> -- >> View this message in context: http://r.789695.n4.nabble.com/xts-POSIXct-index-format-tp3336136p3336136.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> 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. >> > > ______________________________________________ > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
Seemingly Similar Threads
- XTS : merge.xts seems to have problem with character vectors
- Create a zoo/xts Time Series with Millisecond jumps
- Aggragating subsets of data in larger vector with sapply
- Regex to remove last character
- Isn't aggreate.zoo supposed to work with POSIXct (zoo/TTR/xts issue)?