Hello, my series of dates look like [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" [9] "2012-05-31 02:30:00 UTC" "2012-05-31 00:30:00 UTC" [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" ... I'd like to subset this to four series 1) [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" [9] "2012-05-31 02:30:00 UTC" [10] "2012-05-31 18:30:00 UTC" "2012-05-31 19:30:00 UTC" ... 2) "2012-05-31 00:30:00 UTC" -> [1] [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" -> [2,3] [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" [10] "2012-06-01 00:30:00 UTC" 3) [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" ... so that I can plot data for each of the series separately without e.g. data at hour "2012-05-31 02:30:00 UTC" connecting in the figure to "2012-05-31 00:30:00 UTC" Basically, cycling through the series with period 9 Thanks for any suggestions/help, thanks, Mark [[alternative HTML version deleted]]
Is this a one off or not? Why not do it manually? If you need to write a function some example data would be helpful. On Thu, Dec 13, 2012 at 10:52 AM, m p <mzp3769@gmail.com> wrote:> Hello, > my series of dates look like > > [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" > [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" > [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" > [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" > [9] "2012-05-31 02:30:00 UTC" "2012-05-31 00:30:00 UTC" > [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" > [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" > [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" > [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" > [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" > ... > > I'd like to subset this to four series > > 1) > [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" > [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" > [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" > [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" > [9] "2012-05-31 02:30:00 UTC" > > [10] "2012-05-31 18:30:00 UTC" "2012-05-31 19:30:00 UTC" > ... > > 2) > "2012-05-31 00:30:00 UTC" > -> [1] > [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" -> [2,3] > [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" > [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" > [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" > > [10] "2012-06-01 00:30:00 UTC" > > > 3) > [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" > ... > > so that I can plot data for each of the series separately without e.g. data > at hour "2012-05-31 02:30:00 UTC" connecting in the figure to "2012-05-31 > 00:30:00 UTC" > > Basically, cycling through the series with period 9 > > Thanks for any suggestions/help, > thanks, > > Mark > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Stephen Sefick ************************************************** Auburn University Biological Sciences 331 Funchess Hall Auburn, Alabama 36849 ************************************************** sas0025@auburn.edu http://www.auburn.edu/~sas0025 ************************************************** Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis "A big computer, a complex algorithm and a long time does not equal science." -Robert Gentleman [[alternative HTML version deleted]]
On Dec 13, 2012, at 8:52 AM, m p wrote:> Hello, > my series of dates look like > > [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" > [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" > [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" > [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" > [9] "2012-05-31 02:30:00 UTC" "2012-05-31 00:30:00 UTC" > [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" > [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" > [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" > [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" > [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" > ... >Better would have been series <- seq(as.POSIXct("2012-05-30 18:30:00", tz= "UTC"), length=40, by="1 hour")> I'd like to subset this to four seriesAlthough you latter describe the problem differently, so I am following that description. See if this split approach with modulo arithmetic is helpful: split(series, (0:length(series)-1) %/% 9 ) -- David.> > 1) > [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" > [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" > [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" > [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" > [9] "2012-05-31 02:30:00 UTC" > > [10] "2012-05-31 18:30:00 UTC" "2012-05-31 19:30:00 UTC" > ... > > 2) > "2012-05-31 00:30:00 > UTC" > -> [1] > [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" -> [2,3] > [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" > [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" > [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" > > [10] "2012-06-01 00:30:00 UTC" > > > 3) > [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" > ... > > so that I can plot data for each of the series separately without > e.g. data > at hour "2012-05-31 02:30:00 UTC" connecting in the figure to > "2012-05-31 > 00:30:00 UTC" > > Basically, cycling through the series with period 9 > > Thanks for any suggestions/help, > thanks, > > Mark > > [[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.David Winsemius, MD Alameda, CA, USA
Hi, Try this: seq1<-seq(from=as.POSIXct("2012-05-30 18:30:00",tz="UTC"),to=as.POSIXct("2012-05-31 02:30:00",tz="UTC"),by="1 hour") seq2<-seq(from=as.POSIXct("2012-05-31 00:30:00",tz="UTC"),to=as.POSIXct("2012-05-31 08:30:00",tz="UTC"),by="1 hour") seq3<-seq(from=as.POSIXct("2012-05-31 06:30:00",tz="UTC"),to=as.POSIXct("2012-05-31 07:30:00",tz="UTC"),by="1 hour") Sys.setenv(TZ="UTC") ?Series1<-c(seq1,seq2,seq3) ?split(Series1,rep(1:3,each=9)) #or individually if it is a small dataset Series1[1:9] Series1[10:18] etc. A.K. ----- Original Message ----- From: m p <mzp3769 at gmail.com> To: r-help at stat.math.ethz.ch Cc: Sent: Thursday, December 13, 2012 11:52 AM Subject: [R] subsetting time series Hello, my series of dates look like ? [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" ? [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" ? [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" ? [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" ? [9] "2012-05-31 02:30:00 UTC" "2012-05-31 00:30:00 UTC" [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" ... I'd like to subset this to four series 1) ? [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC" ? [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC" ? [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC" ? [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC" ? [9] "2012-05-31 02:30:00 UTC" [10] "2012-05-31 18:30:00 UTC" "2012-05-31 19:30:00 UTC" ... 2) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "2012-05-31 00:30:00 UTC" -> [1] [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" -> [2,3] [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC" [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC" [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC" [10] "2012-06-01 00:30:00 UTC" 3) [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC" ... so that I can plot data for each of the series separately without e.g. data at hour? "2012-05-31 02:30:00 UTC"? connecting in the figure to "2012-05-31 00:30:00 UTC" Basically, cycling through the series with period 9 Thanks for any suggestions/help, thanks, Mark ??? [[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.