[R-SIG-Finance] Split by date

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Jul 8 00:53:38 CEST 2010


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:
> strsplit(str, ",(?=[[:digit:]]{8})", perl=TRUE)
[[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:
> Hello Artem,
>
> I can just give you a pointer to a possible solution. I assume, that you
> have a string of this form:
> "20100501,125201,23.52,20100501,125205,23.62" and so on.
> So you will need to split this string. First you should split this string
> for every datepoint, I don't get It why my R-solution doesn't work, but in
> JAVA you could use this : ",(?=\d{8})" as a regular expression to split your
> string. My approach in R would be
>
> str <- "20100501,125201,23.52,20100501,125205,23.62"
> strsplit(str, ",(?=[[:digit:]]{8})")
>
> but I just get an error, that my regexp is wrong. (the java solution
> works...) Maybe you can see a possible solution for your problem now. If
> not, please try to solve the problem in the R-snippet and than we can
> proceed
>
> regards,
>
> Konrad Hoppe
> www.konrad-hoppe.com
>
> -----Ursprüngliche Nachricht-----
> Von: r-sig-finance-bounces at stat.math.ethz.ch
> [mailto:r-sig-finance-bounces at stat.math.ethz.ch] Im Auftrag von Artem
> Simonov
> Gesendet: Mittwoch, 7. Juli 2010 23:07
> An: r-sig-finance at stat.math.ethz.ch
> Betreff: [R-SIG-Finance] Split by date
>
> Hello All!
>  I have a file with quotes for 3 months (data format: <DATE>(yyyymmdd),
> <TIME>(hhmmss), <CLOSE>). I'm trying to get each day in a single array
> and analyze it separately. Could you please tell me how to solve this
> problem?
>  Thanks in advance for your answer!
>
> Artem Simonov, Russia, Perm.
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
>
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> 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.
> -- Also note that this is not the r-help list where general R questions should go.
>



More information about the R-SIG-Finance mailing list