[R] handling the output of strsplit

jim holtman jholtman at gmail.com
Mon Jun 23 14:44:41 CEST 2008


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?



More information about the R-help mailing list