Skip to content
Prev 2460 / 15274 Next

Date from csv as date for ts

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: