[R] xts POSIXct index format

David Winsemius dwinsemius at comcast.net
Sat Mar 5 17:22:46 CET 2011


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



More information about the R-help mailing list