[R-SIG-Finance] Time indexation after selection in an xts object

Joshua Ulrich josh.m.ulrich at gmail.com
Tue May 1 15:40:43 CEST 2012


I cannot replicate this behavior.  Please provide a reproducible example.

> library(xts)
> set.seed(21)
> x <- .xts(trunc(runif(1e4)*10), 1:1e4, dimnames=list(NULL,"SIZE"))
> s <- cumsum(x$SIZE['1969-12-31'])
> head(s)
                    SIZE
1969-12-31 18:00:01    7
1969-12-31 18:00:02    9
1969-12-31 18:00:03   15
1969-12-31 18:00:04   16
1969-12-31 18:00:05   25
1969-12-31 18:00:06   34
> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] xts_0.8-6 zoo_1.7-7

loaded via a namespace (and not attached):
[1] grid_2.15.0    lattice_0.20-6

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

R/Finance 2012: Applied Finance with R
www.RinFinance.com


On Tue, May 1, 2012 at 6:04 AM, Karim <kktrash.k at gmail.com> wrote:
>
> Hi,
>
> My xts object : SP500TiSa
>
> > head(SP500TiSa)
>
>                         BID  OFR   PRICE SIZE
> 2012-01-23 06:00:58 1306.75 1307 1307.00    2
> 2012-01-23 06:00:58 1306.75 1307 1306.75    6
> 2012-01-23 06:00:58 1306.75 1307 1307.00    1
> 2012-01-23 06:00:58 1306.75 1307 1307.00    2
> 2012-01-23 06:00:59 1306.75 1307 1307.00    1
> 2012-01-23 06:00:59 1306.75 1307 1307.00    1
>
> What I want to do is to calculate the cumulated sum of the column SIZE of the records of day 2012-01-24 but I want the resulting selection to keep the time information
>
> > s=cumsum(SP500TiSa$SIZE['2012-01-24'])
>
>
> When I plot s, that’s ok, I have the time information on the x-axis of the graph :
>
> > plot(s,type="l")
>
>
> But when I display s on the console :
>
> > head(s)
>            SIZE
> 2012-01-24    4
> 2012-01-24    5
> 2012-01-24    6
> 2012-01-24   16
> 2012-01-24   17
> 2012-01-24   32
>
> We have only the day information on the index. The time info is lost, how to keep it ?
>
> Thank you
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list