[R] Finding minimum of time subset

Tim Clark mudiver1200 at yahoo.com
Fri Aug 14 21:15:04 CEST 2009


Thanks for everyones help and for the alternate ways of doing this.  I am always amazed at how many solutions this list comes up with for things I get stuck on!  It really helps us non-programmers learn R!

Aloha,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 8/14/09, Henrique Dallazuanna <wwwhsd at gmail.com> wrote:

> From: Henrique Dallazuanna <wwwhsd at gmail.com>
> Subject: Re: [R] Finding minimum of time subset
> To: "Tim Clark" <mudiver1200 at yahoo.com>
> Cc: r-help at r-project.org
> Date: Friday, August 14, 2009, 7:19 AM
> Try this also:
> 
> times <- as.POSIXlt(mytime, format =
> "%H:%M:%S")
> subTimes <- times[times[['min']] %in%
> c(0,15,30,45)]
> format(subTimes[!duplicated(format(subTimes,
> "%H:%M"))], "%H:%M:%S")
> 
> 
> On Thu, Aug 13, 2009 at 5:10 PM,
> Tim Clark <mudiver1200 at yahoo.com>
> wrote:
> 
> Dear List,
> 
> 
> 
> I have a data frame of data taken every few seconds.  I
> would like to subset the data to retain only the data taken
> on the quarter hour, and as close to the quarter hour as
> possible.  So far I have figured out how to subset the data
> to the quarter hour, but not how to keep only the minimum
> time for each quarter hour.
> 
> 
> 
> 
> For example:
> 
> mytime<-c("12:00:00","12:00:05","12:15:05","12:15:06","12:20:00","12:30:01","12:45:01","13:00:00","13:15:02")
> 
> subtime<-grep(pattern="[[:digit:]]+[[:punct:]]00[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]15[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]30[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]45[[:punct:]][[:digit:]]+",mytime)
> 
> 
> mytime[subtime]
> 
> 
> 
> [1] "12:00:00" "12:00:05"
> "12:15:05" "12:15:06"
> "12:30:01" "12:45:01"
> "13:00:00" "13:15:02"
> 
> 
> 
> This gives me the data taken at quarter hour intervals
> (removes 12:20:00) but I am still left with multiple values
> at the quarter hours.
> 
> 
> 
> I would like to obtain:
> 
> 
> 
> "12:00:00" "12:15:05"
> "12:30:01" "12:45:01"
> "13:00:00" "13:15:02"
> 
> 
> 
> Thanks!
> 
> 
> 
> Tim
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Tim Clark
> 
> Department of Zoology
> 
> University of Hawaii
> 
> 
> 
> ______________________________________________
> 
> 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.
> 
> 
> 
> 
> -- 
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
> 
> 







More information about the R-help mailing list