Hi, I have a data frame with two columns: dt and tf. The dt column is datetime and the tf column is a temperature. dt tf 1 2009-06-20 00:53:00 73 2 2009-06-20 01:08:00 73 3 2009-06-20 01:44:00 72 4 2009-06-20 01:53:00 71 5 2009-06-20 02:07:00 72 ... I need a subset of the rows where the minutes are 53. The hour is immaterial. I can not find a wildcard character to use to select the rows. as.character(wtd$dt) %in% "2009-06-21 ??:53:00" or as.character(wtd $dt) %in% "2009-06-21 **:53:00" does not work. What would you recommend? Thanks, Keith Jones, Ph.D. VTS Pumps
Convert dt to POSIXct class: wtd$dt <- as.POSIXct(wtd$dt) subset(wtd, format(dt, '%M') == 53) On Mon, Jun 22, 2009 at 9:58 PM, Keith Jones <keithlj@keithljelp.com> wrote:> Hi, > > I have a data frame with two columns: dt and tf. The dt column is datetime > and the tf column is a temperature. > > dt tf > 1 2009-06-20 00:53:00 73 > 2 2009-06-20 01:08:00 73 > 3 2009-06-20 01:44:00 72 > 4 2009-06-20 01:53:00 71 > 5 2009-06-20 02:07:00 72 > ... > > I need a subset of the rows where the minutes are 53. The hour is > immaterial. I can not find a wildcard character to use to select the rows. > > as.character(wtd$dt) %in% "2009-06-21 ??:53:00" or as.character(wtd$dt) > %in% "2009-06-21 **:53:00" does not work. > > What would you recommend? > > Thanks, > > Keith Jones, Ph.D. > VTS Pumps > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Try this:> Lines <- "dt,tf+ 2009-06-20 00:53:00,73 + 2009-06-20 01:08:00,73 + 2009-06-20 01:44:00,72 + 2009-06-20 01:53:00,71 + 2009-06-20 02:07:00,72"> DF <- read.csv(textConnection(Lines), colClasses = c("POSIXct", "numeric")) > DF[format(DF$dt, "%M") == "53",]dt tf 1 2009-06-20 00:53:00 73 4 2009-06-20 01:53:00 71 On Mon, Jun 22, 2009 at 8:58 PM, Keith Jones<keithlj at keithljelp.com> wrote:> Hi, > > I have a data frame with two columns: dt and tf. ?The dt column is datetime > and the tf column is a temperature. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dt ?tf > 1 2009-06-20 00:53:00 73 > 2 2009-06-20 01:08:00 73 > 3 2009-06-20 01:44:00 72 > 4 2009-06-20 01:53:00 71 > 5 2009-06-20 02:07:00 72 > ... > > I need a subset of the rows where the minutes are 53. ?The hour is > immaterial. ?I can not find a wildcard character to use to select the rows. > > as.character(wtd$dt) %in% "2009-06-21 ??:53:00" or as.character(wtd$dt) %in% > "2009-06-21 **:53:00" does not work. > > What would you recommend? > > Thanks, > > Keith Jones, Ph.D. > VTS Pumps > > ______________________________________________ > 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. >
If you want to use regular expressions, try:> xV1 V2 V3 V4 1 1 2009-06-20 00:53:00 73 2 2 2009-06-20 01:08:00 73 3 3 2009-06-20 01:44:00 72 4 4 2009-06-20 01:53:00 71 5 5 2009-06-20 02:07:00 72> x[grep(":53:", x$V3),]V1 V2 V3 V4 1 1 2009-06-20 00:53:00 73 4 4 2009-06-20 01:53:00 71>On Mon, Jun 22, 2009 at 8:58 PM, Keith Jones <keithlj@keithljelp.com> wrote:> Hi, > > I have a data frame with two columns: dt and tf. The dt column is datetime > and the tf column is a temperature. > > dt tf > 1 2009-06-20 00:53:00 73 > 2 2009-06-20 01:08:00 73 > 3 2009-06-20 01:44:00 72 > 4 2009-06-20 01:53:00 71 > 5 2009-06-20 02:07:00 72 > ... > > I need a subset of the rows where the minutes are 53. The hour is > immaterial. I can not find a wildcard character to use to select the rows. > > as.character(wtd$dt) %in% "2009-06-21 ??:53:00" or as.character(wtd$dt) > %in% "2009-06-21 **:53:00" does not work. > > What would you recommend? > > Thanks, > > Keith Jones, Ph.D. > VTS Pumps > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]