[R] handling the output of strsplit

Patrick Connolly p_connolly at slingshot.co.nz
Mon Jun 23 12:29:05 CEST 2008


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



More information about the R-help mailing list