Re: [R] handling the output of strsplit

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 23 Jun 2008 08:44:41 -0400

One way, if you are unsure of your data, is to append two additional zeros on to the strings:

> strptime("23h", format="%Hh%M")
[1] NA
> strptime(paste("23h", "00", sep=""), format="%Hh%M")
[1] "2008-06-23 23:00:00 GMT"
> strptime(paste("23h04", "00", sep=""), format="%Hh%M")
[1] "2008-06-23 23:04:00 GMT"
>

On Mon, Jun 23, 2008 at 6:29 AM, Patrick Connolly <p_connolly_at_slingshot.co.nz> wrote:
> On Sat, 21-Jun-2008 at 05:33AM -0700, Mark Difford wrote:
>
> |>
> |> Hi Denis,
> |>
> |> >> h = c("3h30", "6h30", "9h40", "11h25", "14h00",
> |> >> "15h55", "23h")
> |>
> |> >> I could not figure out how to use chron to import this into times, so
> |> >> I tried to extract the hours and minutes on my own.
> |>
> |> Look at ?strptime for this:
> |> ##
> |> strptime("6h30", format="%Ih%M")
> |> [1] "2008-06-21 06:30:00"
>
> That's a neat approach, however, it won't work for this one:
>> strptime("14h00", format="%Ih%M")
> [1] NA
>
> But this will:
>> strptime("14h00", format="%Hh%M")
> [1] "2008-06-23 14:00:00"
>
> However (again), *it* also won't work here:
>
>> strptime("23h", format="%Hh%M")
> [1] NA
>>
>
> So it's back to the strsplit method for it unless you can get a zero
> after the 'h', and the best way of doing that would depend on how your
> real data is being entered.
>
>
> --
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
> ___ Patrick Connolly
> {~._.~} Great minds discuss ideas
> _( Y )_ Middle minds discuss events
> (:_~*~_:) Small minds discuss people
> (_)-(_) ..... Anon
>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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.
Received on Mon 23 Jun 2008 - 12:52:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 13:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive