[R-SIG-Finance] [R-sig-finance] Date from csv as date for ts

Gabor Grothendieck ggrothendieck at gmail.com
Tue May 6 17:55:14 CEST 2008


Try this where textConnection(Lines) would be replaced by "myfile.csv"
or whatever your file name.  Also you can replace each of the two occurrences
of the word zoo below with xts and it will give xts objects instead.
Read the three
vignettes that come with zoo for more info.

library(zoo)
Lines <- "Name,Date,Returns
A,31/01/2000,1
A,01/02/2000,2
B,31/01/2000,1
B,01/02/2000,2
B,01/03/2000,3
"
DF <- read.csv(textConnection(Lines))
f <- function(x) zoo(x$Returns, as.Date(x$Date, "%d/%m/%Y"))
do.call(merge, by(DF, DF$Name, f))


On Tue, May 6, 2008 at 11:17 AM, R at Nabble <vlanschot at yahoo.com> wrote:
>
> Apologies if this has been answered elsewhere, but I couldn't find it.
>
> Basically, I dump securities' return- data in a csv-file with 3 columns:
> Name, Date, and Returns. In other words, the Date column contains multiple
> entries for each date, namely one for each security. I figured out how to
> extract these dates in one vector with strings from "31/01/2000" to
> 31/03/2008", which I then transformed via the as.Date function. I
> subsequently created a return-matrix via cbind for each security.
>
> My question/problem is, I have been unable to use the date-vector as
> date-input for my ts-object. Looking at the smallcap.ts-example on page 14
> of the fPortfolio Package pdf, I'd like to somehow combine my Date-vector
> with my return-matrix into one large matrix for input in fPortfolio. Using
> cbind, etc. leads to errors.
>
> Clearly I'm on a steep learning curve, so any help appreciated.
>
> Thx,
>
> R at N
> --
> View this message in context: http://www.nabble.com/Date-from-csv-as-date-for-ts-tp17085476p17085476.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> 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