[R] Replace split with regex for speed ?

rivercode aquanyc at gmail.com
Fri Mar 18 03:01:06 CET 2011


Have timestamp in format HH:MM:SS.MMM.UUU and need to remove the last "." so
it is in format HH:MM:SS.MMMUUU.

What is the fastest way to do this, since it has to be repeated on millions
of rows. Should I use regex ?

Currently doing it with a string split, which is slow:

 >head(ts)
[1]  09:30:00.000.245  09:30:00.000.256  09:30:00.000.633  09:30:00.001.309 
09:30:00.003.635  09:30:00.026.370


  ts = strsplit(ts, ".", fixed = TRUE)
  ts=lapply(ts, function(x) { paste(x[1], ".", x[2], x[3], sep="") } ) 	#
Remove last . from timestamp, from HH:MM:SS.MMM.UUU to HH:MM:SS.MMMUUU
  ts = unlist(ts)

Thanks,
Chris

--
View this message in context: http://r.789695.n4.nabble.com/Replace-split-with-regex-for-speed-tp3386098p3386098.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list