Dirk Eddelbuettel — written Jan 17, 2013 — source
A recent post showed how to access the
attributes of an xts object.
We used an xts
object as these are powerful and popular—but any R object
using attributed could be used to illustrate the point.
In this short post, we show how one can also do the inverse in order to create an xts object at the C++ source level.
We use a somewhat useless object with values from 1:10
index by
dates in the same range. As zero corresponds to the epoch, these
will be early 1970-dates. But the values do not matter when showing
the principle.
We can run this function, and look at the (numerous) attributes in the generated object:
[,1] 1970-01-02 1 1970-01-03 2 1970-01-04 3 1970-01-05 4 1970-01-06 5 1970-01-07 6 1970-01-08 7 1970-01-09 8 1970-01-10 9 1970-01-11 10
$dim [1] 10 1 $index [1] 86400 172800 259200 345600 432000 518400 604800 691200 777600 864000 attr(,"tzone") [1] "UTC" attr(,"tclass") [1] "Date" $class [1] "xts" "zoo" $.indexCLASS [1] "Date" $tclass [1] "Date" $.indexTZ [1] "UTC" $tzone [1] "UTC"
It turns out that creating an xts
object the usual way creates an object that is equal:
[1] TRUE
So now we can create xts
objects at the source level.
Upated to add sv
and ev
start and end values.