[R-SIG-Finance] xts question: how to get previous row?

Murali.MENON at fortisinvestments.com Murali.MENON at fortisinvestments.com
Mon Jul 13 11:47:05 CEST 2009


This appears to work:

> aapl <- as.xts(read.zoo(textConnection("2007-04-20,      90.97
+ 2007-04-23,      93.51
+ 2007-04-24,      93.24
+ 2007-04-25,      95.35
+ 2007-04-26,      98.84
+ 2007-04-27,      99.92
+ 2007-04-30,      99.80
+ 2007-05-01,      99.47
+ 2007-05-02,     100.39
+ 2007-05-03,     100.40
+ 2007-05-04,     100.81"), sep=","))

> aapl[grep("2007-04-30", index(aapl)) - 1]
            [,1]
2007-04-27 99.92

Murali

-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Mark
Breman
Sent: 13 July 2009 07:57
To: r-sig-finance at stat.math.ethz.ch
Subject: [R-SIG-Finance] xts question: how to get previous row?

I have a really basic question but I can't find an answer for it.

Supose I have this xts timeseries called aapl:
           AAPL.Close
2007-04-20      90.97
2007-04-23      93.51
2007-04-24      93.24
2007-04-25      95.35
2007-04-26      98.84
2007-04-27      99.92
2007-04-30      99.80
2007-05-01      99.47
2007-05-02     100.39
2007-05-03     100.40
2007-05-04     100.81

and supose I have a reference to a row in this series (i.e.
aapl["2007-04-30"]), what is the easiest way to select the previous row
(i.e. the row with index 2007-04-27) from the series?

Thanks,

-Mark-

	[[alternative HTML version deleted]]

_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.



More information about the R-SIG-Finance mailing list