Dear R-helpers, I have the following data: y happenat x 5185 (07/22/05 00:05:14) 14 5186 (07/22/05 00:15:14) 14 5187 (07/22/05 00:25:14) 14 5188 (07/22/05 00:35:14) 14 ...... I want to choose between 07/25/05 15:30:00 and 07/26/05 12:30:00. Anybody had experience in handling this kind of data? Is there a simple way to subset by the variable 'happenat'? Thanks.
If happenat is not a datetime value, convert it with strptime(). Then, one solution is to transform it in the following way: num.time <- as.numeric(format(happenat,"%Y%m%d%H%M%S")) This way, 07/22/05 00:05:14 becomes 20050722000514, and you can subset your data frame with dfr[which(num.time >= 20050725153000 & num.time <= 20050726123000),] hth, b.> -----Original Message----- > From: Kerry Bush [mailto:kerryrekky at yahoo.com] > Sent: Tuesday, July 26, 2005 3:54 PM > To: r-help at stat.math.ethz.ch > Subject: [R] choose between dates and times > > > Dear R-helpers, > I have the following data: > > y happenat x > 5185 (07/22/05 00:05:14) 14 > 5186 (07/22/05 00:15:14) 14 > 5187 (07/22/05 00:25:14) 14 > 5188 (07/22/05 00:35:14) 14 > ...... > > I want to choose between 07/25/05 15:30:00 and > 07/26/05 12:30:00. Anybody had experience in handling > this kind of data? Is there a simple way to subset by > the variable 'happenat'? Thanks. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Kerry Bush <kerryrekky at yahoo.com> writes:> Dear R-helpers, > I have the following data: > > y happenat x > 5185 (07/22/05 00:05:14) 14 > 5186 (07/22/05 00:15:14) 14 > 5187 (07/22/05 00:25:14) 14 > 5188 (07/22/05 00:35:14) 14 > ...... > > I want to choose between 07/25/05 15:30:00 and > 07/26/05 12:30:00. Anybody had experience in handling > this kind of data? Is there a simple way to subset by > the variable 'happenat'? Thanks.Simple, perhaps not. This stuff always gets a little heavy, but start here:> strptime("(07/22/05 00:05:14)",format="(%m/%d/%y %H:%M:%S)") >+ as.POSIXct("2005-07-22 00:06:00") [1] FALSE> strptime("(07/22/05 00:05:14)",format="(%m/%d/%y %H:%M:%S)") >+ as.POSIXct("2005-07-22 00:05:00") [1] TRUE Once you figure out how this works, the rest should follow. -- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907