[R-SIG-Finance] [R-sig-finance] converting to timeSeries
Yohan Chalabi
chalabi at phys.ethz.ch
Sat Jan 3 09:19:20 CET 2009
>>>> "P" == patzoul <patzoul at free.fr>
>>>> on Tue, 30 Dec 2008 12:46:29 -0800 (PST)
P>
P> I am loading data from a csv file:
P> x = read.csv(XFR00104.txt, header = FALSE)
P>
P> The format is like this:
P> V1 V2 V3 V4 V5 V6 V7
P> 1 XFR0010411884 12/31/07 1 55.64 55.32 55.62 7244
P> 2 XFR0010411884 01/02/08 1 56.80 54.50 56.75 58724
P> 3 XFR0010411884 01/03/08 1 57.20 56.42 56.67 156879
P> 4 XFR0010411884 01/04/08 1 58.98 56.28 58.43 138630
P>
P> I would like to convert it to a timeSeries.
P>
P> As a first step I converted the second column into dates:
P> x[,2] = as.Date(x[,2], format = %m/%d/%y)
P>
P> and then used the as.timeSeries function:
P> y = as.timeSeries(x[2:6])
P>
P> but lost all the date information:
P> V3 V4 V5 V6
P> 1 1 55.64 55.32 55.62
P> 2 1 56.80 54.50 56.75
P> 3 1 57.20 56.42 56.67
P> 4 1 58.98 56.28 58.43
P>
P> What do I need to do to get a proper timeSeries?
P>
P>
read the manual pages ...
?timeSeries
my guess would be :
timeSeries(data = x[2:6], charvec = x[,2], format = "%m/%d/%y")
More information about the R-SIG-Finance
mailing list