[R] Selecting timestamps

From: Lauri Nikkinen <lauri.nikkinen_at_iki.fi>
Date: Thu, 21 Feb 2008 09:03:59 +0200


I have two vectors (of timestamps)

d1 <- as.POSIXct(strptime("2.2.2002 07:00", format="%d.%m.%Y %H:%M"))
d2 <- as.POSIXct(strptime("4.2.2002 07:00", format="%d.%m.%Y %H:%M"))
seq1 <- seq(d1, d2, "hours")

d3 <- as.POSIXct(strptime("2.2.2002 15:22", format="%d.%m.%Y %H:%M"))
d4 <- as.POSIXct(strptime("3.2.2002 18:12", format="%d.%m.%Y %H:%M"))
seq2 <- seq(d3, d4, "hours")


How to select timestamps from seq1 which are just before and after of particular timestamp in seq2?
The resulting vector should look like this in this example:

"2002-02-02 15:00:00 Normaaliaika"
"2002-02-02 16:00:00 Normaaliaika"
"2002-02-02 16:00:00 Normaaliaika"
"2002-02-02 17:00:00 Normaaliaika"
"2002-02-02 17:00:00 Normaaliaika"
"2002-02-02 18:00:00 Normaaliaika"
"2002-02-02 18:00:00 Normaaliaika"


Thank you,

> sessionInfo()
R version 2.6.0 (2007-10-03)


attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] RODBC_1.2-3 loaded via a namespace (and not attached): [1] tools_2.6.0

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. Received on Thu 21 Feb 2008 - 07:14:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Feb 2008 - 09:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive