Hi, I 'd like to know how to extract an interval of "hour:minute" type from a column of POSIXlt POSIXct type. For instance: my_data.csv: 4352;2011-09-02 21:30:00;3242; 4352;2011-09-02 21:31:00;3315; 4352;2011-09-02 21:32:00;4241; 4352;2011-09-02 21:33:00;5394; ... 4352;2011-09-02 01:02:00;67; 4352;2011-09-02 01:03:00;67; 4352;2011-09-02 01:04:00;67; .... I loaded my_data.csv into a data.frame. I 'd like to select rows where times T satisfies 21:30:00<= T <=22:30:00. I do not worry about the date. I just need the time to select the interval Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/How-to-extract-an-interval-of-hour-minute-type-tp4237144p4237144.html Sent from the R help mailing list archive at Nabble.com.
How to extract an interval of "hour:minute" type
4 messages · ikuzar, jim holtman
Here is one way:
x <- read.table(text = "4352;2011-09-02 21:30:00;3242;
+ 4352;2011-09-02 21:31:00;3315; + 4352;2011-09-02 21:32:00;4241; + 4352;2011-09-02 21:33:00;5394;", sep = ';', as.is = TRUE)
# create a 'character' of just the time. If the data is of # the format above, 'substring' can be used x$time <- substring(x$V2, 12, 16) subset(x, time >= '21:31' & time <= '21:32')
V1 V2 V3 V4 time 2 4352 2011-09-02 21:31:00 3315 NA 21:31 3 4352 2011-09-02 21:32:00 4241 NA 21:32
On Tue, Dec 27, 2011 at 9:02 AM, ikuzar <razuki at hotmail.fr> wrote:
Hi, I 'd like to know how to extract an interval of "hour:minute" type from a column of POSIXlt POSIXct type. For instance: my_data.csv: 4352;2011-09-02 21:30:00;3242; 4352;2011-09-02 21:31:00;3315; 4352;2011-09-02 21:32:00;4241; 4352;2011-09-02 21:33:00;5394; ... 4352;2011-09-02 01:02:00;67; 4352;2011-09-02 01:03:00;67; 4352;2011-09-02 01:04:00;67; .... I loaded my_data.csv into a data.frame. I 'd like to select rows where times T satisfies 21:30:00<= T <=22:30:00. I do not worry about the date. I just need ?the time to select the interval Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/How-to-extract-an-interval-of-hour-minute-type-tp4237144p4237144.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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 Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
Jim Holtman > I'd like to compare "hour1:min1:sec1" with "hour2:min2:sec2". I know how to do to compare "year1-mon1-day1 hour1:min1:sec1" with "year2-mon2-day2 hour2:min2:sec2" by converting 'character' into POSIXlt but I'd like to konw if there is another way to do this comparison without converting my POSIXLT column into 'character' . If possible, I want to work with DateTime format and not with string so that I do not make new conversions -- View this message in context: http://r.789695.n4.nabble.com/How-to-extract-an-interval-of-hour-minute-type-tp4237144p4237800.html Sent from the R help mailing list archive at Nabble.com.
I think one of the suggestion was to use something like, assuming you have the time in POSIXct format(x$time, format = "%H:%M:%S") >= "20:10:00" & format(x$time, format = "%H:%M:%S") <= "21:00:00" This takes the 'date' out of the equation. You can always write a function to do this for you.
On Tue, Dec 27, 2011 at 1:02 PM, ikuzar <razuki at hotmail.fr> wrote:
Jim Holtman > I'd like to compare "hour1:min1:sec1" with "hour2:min2:sec2". I know how to do to compare "year1-mon1-day1 hour1:min1:sec1" with "year2-mon2-day2 hour2:min2:sec2" by converting 'character' into POSIXlt but I'd like to konw if there is another way to do this comparison without converting my POSIXLT column into 'character' . If possible, I want to work with DateTime format and not with string so that I do not make new conversions -- View this message in context: http://r.789695.n4.nabble.com/How-to-extract-an-interval-of-hour-minute-type-tp4237144p4237800.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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 Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.