Skip to content
Prev 6362 / 15274 Next

Split by date

Artem,

Try this:

Lines <-
"Date,Time,Close
20100707,100944,10.10
20100707,101023,10.12
20100708,110944,10.15
20100708,111023,10.13"

x <- read.csv(con <- textConnection(Lines)); close(con)

x$DateTime <- as.POSIXct(paste(x$Date,x$Time),format="%Y%m%d %H%M%S")
x <- as.xts(x$Close,x$DateTime)

epDays <- endpoints(x,"days")

for(i in 2:NROW(epDays)) {
  assign(paste("x",format(index(x)[i],"%Y%m%d"),sep=""),x[(i-1):i,])
}


Konrad,

You get an error because ",(?=[[:digit:]]{8})" is a PERL regular expression:
[[1]]
[1] "20100501,125201,23.52" "20100501,125205,23.62"


Best,
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com
On Wed, Jul 7, 2010 at 5:22 PM, Konrad Hoppe <konradhoppe at hotmail.de> wrote: