[R-SIG-Finance] Split by date

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jul 8 01:07:20 CEST 2010


On Wed, Jul 7, 2010 at 5:07 PM, Artem Simonov <scherrzo at rambler.ru> wrote:
> 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!
>

Using Lines from one of the other answers:



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

library(zoo)
library(chron)

# function to convert date/time to chron object
dt <- function(x, format) as.chron(paste(x[,1], x[,2]),
		format = "%Y%m%d %H%M%S")

# read in converting date/times using dt
# First arg might be "myfile.csv" in reality.
z <- read.zoo(textConnection(Lines), header = TRUE, sep = ",",
		index = 1:2, FUN = dt)

# create a list with one component per day
split(z, as.Date(time(z)))



More information about the R-SIG-Finance mailing list