Re: Minutes and Hours

Rod Tjoelker 865-3197 (tjoelker@redwood.rt.cs.boeing.com)
Thu, 29 Jan 1998 11:40:36 -0800


>
> On Wed, 28 Jan 1998, Catherine Collins wrote:
>
> > On a related topic, can S-Plus unpack expressions like "5:30:05 AM"? Has
> > anybody written anything to do this?
> >

Here's a little function that works on vectors of strings of time
values like the one you specify:

read.time <- function(x, sep = ":", pm = T) {
nc <- nchar(x)
if(pm) {
ap <- substring(x, nc - 1, nc)
x <- substring(x, 1, nc - 2)
}
out <- unpaste(x, sep = sep)
out$pm <- ap
names(out) <- c("hr","min","sec","pm")
return(out)
}

I hope you find this useful.

------------------
Rod Tjoelker
Applied Statistics
The Boeing Company
------------------