Re: [R] handling the output of strsplit

From: Patrick Connolly <p_connolly_at_slingshot.co.nz>
Date: Mon, 23 Jun 2008 22:29:05 +1200

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.
Received on Mon 23 Jun 2008 - 10:33:01 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