[R] Two time measures
jim holtman
jholtman at gmail.com
Sat Nov 27 23:43:32 CET 2010
Try this:
> x <- structure(list(Date = c("01/09/2009", "01/09/2009", "01/09/2009",
+ "01/09/2009", "01/09/2009", "01/09/2009", "02/09/2009", "02/09/2009",
+ "02/09/2009", "02/09/2009", "02/09/2009", "02/09/2009"), Time = c("10:00",
+ "10:05", "10:10", "16:45", "16:50", "16:55", "10:00", "10:05",
+ "10:10", "16:45", "16:50", "16:55"), Close = c(56567L, 56463L,
+ 56370L, 55771L, 55823L, 55814L, 55626L, 55723L, 55659L, 55742L,
+ 55717L, 55385L)), .Names = c("Date", "Time", "Close"), class =
"data.frame", row.names = c(NA,
+ -12L))
> # convert the time
> x$time <- as.POSIXct(paste(x$Date, x$Time), format='%d/%m/%Y %H:%M')
> # create list
> x.list <- split(x[, c('time','Close')], format(x$time, format = "%Y%m%d"))
> str(x.list)
List of 2
$ 20090901:'data.frame': 6 obs. of 2 variables:
..$ time : POSIXct[1:6], format: "2009-09-01 10:00:00" "2009-09-01
10:05:00" "2009-09-01 10:10:00" ...
..$ Close: int [1:6] 56567 56463 56370 55771 55823 55814
$ 20090902:'data.frame': 6 obs. of 2 variables:
..$ time : POSIXct[1:6], format: "2009-09-02 10:00:00" "2009-09-02
10:05:00" "2009-09-02 10:10:00" ...
..$ Close: int [1:6] 55626 55723 55659 55742 55717 55385
On Sat, Nov 27, 2010 at 5:02 PM, Eduardo de Oliveira Horta
<eduardo.oliveirahorta at gmail.com> wrote:
> Hello!
>
> I have a csv file of intra-day financial data (5-min closing prices) that
> looks like this: (obs - the dates are formated as day/month/year, as is
> usual here in Brazil)
>
> Date;Time;Close
> 01/09/2009;10:00;56567
> 01/09/2009;10:05;56463
> 01/09/2009;10:10;56370
> ##(goes on all day)
> 01/09/2009;16:45;55771
> 01/09/2009;16:50;55823
> 01/09/2009;16:55;55814
> ##(jumps to the subsequent day)
> 02/09/2009;10:00;55626
> 02/09/2009;10:05;55723
> 02/09/2009;10:10;55659
> ##(goes on all day)
> 02/09/2009;16:45;55742
> 02/09/2009;16:50;55717
> 02/09/2009;16:55;55385
> ## (and so on to the next day)
>
> I would like to store the intra-day 5-min prices into a list, where each
> element would represent one day, something like
> list[[1]]
> "price at time 1, day 1"
> "price at time 2, day 1"
> ...
> "price at time n_1, day 1"
>
> list[[2]]
> "price at time 1, day 2"
> "price at time 2, day 2"
> ...
> "price at time n_2, day 2"
>
> and so on.
>
> As the "n_1", "n_2", etc, suggest, each day have its own number of
> observations (this reflects the fact that the market may open and close at
> varying daytimes). I have guessed that a list would be a better way to store
> my data, since a matrix would be filled with NA's and that is not exactly
> what I'm looking for.
>
> Thanks in advance, and best regards,
>
> Eduardo Horta
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list