Skip to content
Prev 181134 / 398503 Next

help with gsub and date pattern

Here are a few more to add to the list.

x <- c("5/31/2009 12:34:00","6/1/2009 1:14:00")

# 1
read.table(textConnection(x), as.is = TRUE)[, 2]

# 2
format(as.POSIXct(x, format = "%m/%d/%Y %H:%M:%S"), "%H:%M:%S")

# 3
library(gsubfn)
strapply(x, "[0-9]*:..:..", simplify = c)

Also see R News 4/1.
On Thu, May 21, 2009 at 5:34 PM, Marc Schwartz <marc_schwartz at me.com> wrote: