You can still use my suggestion (sent offline)

if you have a vector of strings, or just one

 > my.str <- "HH:MM:SS AM"
 > substr(my.str,7,8) <- "00"
 > my.str
[1] "HH:MM:00 AM"

Doesn't matter if it's AM or PM because the function is just acting  
on the 7th and 8th characters.


On Jul 16, 2009, at 1:20 PM, Jason Rupert wrote:

>
> Dang it.  I forgot to mention the actual format of the time is the  
> following:
> "HH:MM:SS AM" or "HH:MM:SS PM"
> And I would still hope for them to end up with the following format:
> "HH:MM:00 AM" or "HH:MM:00 PM"
>
> How would you propose handling that condition?
>
> I tried to use strsplit with items to split on, but no luck.
>
> Thank you again for all your help.
>
>
>
>
> --- On Thu, 7/16/09, Steve Lianoglou  
> <mailinglist.honey...@gmail.com> wrote:
>
>> From: Steve Lianoglou <mailinglist.honey...@gmail.com>
>> Subject: Re: [R] Best way to replace :SS with :00
>> To: "Jason Rupert" <jasonkrup...@yahoo.com>
>> Cc: R-help@r-project.org
>> Date: Thursday, July 16, 2009, 2:58 PM
>> Hi,
>>
>>> Not sure if there is an R way to do this or a regular
>> express way, but here is what I am trying to do.
>>>
>>> I've got lots of data where the format is HH:MM:SS,
>> but I need to format it like HH:MM:00, i.e. round the second
>> down to zero.
>>>
>>> What is the best way to do this?
>>
>>
>> Probably not the best way, but here's one way to do it,
>> step by step:
>>
>> R> a <- rep("HH:MM:SS", 5)
>> R> a
>> [1] "HH:MM:SS" "HH:MM:SS" "HH:MM:SS" "HH:MM:SS" "HH:MM:SS"
>>
>> R> b <- strsplit(a, ":")
>> R> b
>> [[1]]
>> [1] "HH" "MM" "SS"
>>
>> [[2]]
>> [1] "HH" "MM" "SS"
>>
>> [[3]]
>> [1] "HH" "MM" "SS"
>>
>> [[4]]
>> [1] "HH" "MM" "SS"
>>
>> [[5]]
>> [1] "HH" "MM" "SS"
>>
>> R> b2 <- lapply(b, function(pieces)
>> c(pieces[1:2],"00"))
>> R> b2
>> [[1]]
>> [1] "HH" "MM" "00"
>>
>> [[2]]
>> [1] "HH" "MM" "00"
>>
>> [[3]]
>> [1] "HH" "MM" "00"
>>
>> [[4]]
>> [1] "HH" "MM" "00"
>>
>> [[5]]
>> [1] "HH" "MM" "00"
>>
>> R> a2 <- sapply(b2, paste, collapse=':')
>> R> a2
>> [1] "HH:MM:00" "HH:MM:00" "HH:MM:00" "HH:MM:00" "HH:MM:00"
>>
>> HTH,
>> -steve
>>
>> --
>> Steve Lianoglou
>> Graduate Student: Physiology, Biophysics and Systems
>> Biology
>> Weill Medical College of Cornell University
>>
>> Contact Info: http://cbio.mskcc.org/~lianos/contact
>>
>>
>>
>>
>
> ______________________________________________
> 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.




Don McKenzie
Research Ecologist
Pacific Wildland Fire Sciences Lab
US Forest Service

Affiliate Professor
College of Forest Resources and CSES Climate Impacts Group
University of Washington

phone: 206-732-7824
cell: 206-321-5966
d...@u.washington.edu




        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to