[R-SIG-Finance] Reversing date order in CSV file

rex rex at nosyntax.net
Thu Sep 27 07:50:29 CEST 2012


sean fallon <sf99167 at yahoo.com> [2012-09-26 22:31]:
>data<-read.csv("http://ichart.finance.yahoo.com/table.csv?s=INFY.BO&a=08&b=16&c=2008&d=08&e=26&f=2012&g=d&ignore=.csv")
>head(data)
>
>How do I sort the data in reverse i.e the oldest data first. I could open the CSV file in excel and sort decending but is there a line in R I could incorporate to reverse it.

I'd use quantmod.

library(quantmod)
getSymbols('INFY.BO', from='2008-01-01')
head(INFY.BO)
            INFY.BO.Open INFY.BO.High INFY.BO.Low INFY.BO.Close INFY.BO.Volume INFY.BO.Adjusted
2008-01-01       1758.0      1777.15     1743.00       1749.70          51700          1639.38
2008-01-02       1780.0      1785.00     1715.35       1749.40          86700          1639.10
2008-01-03       1740.0      1750.00     1691.60       1713.00         214300          1605.00
2008-01-04       1711.3      1730.00     1680.00       1694.80         134400          1587.94
2008-01-07       1670.0      1681.00     1623.00       1638.10         307500          1534.82
2008-01-08       1651.0      1694.60     1623.20       1662.15         253400          1557.35

class(INFY.BO)
[1] "xts" "zoo"

Which is probably what you want rather than a data.frame.

HTH,

-rex
-- 
Q:  Why do mountain climbers rope themselves together?
A:  To prevent the sensible ones from going home.



More information about the R-SIG-Finance mailing list