r - How to separate date and time -
i`m giving input "a <- [12/dec/2014:05:45:10]" not time-stamp cannot use time , date functions
now want above variable split down 2 parts as:- date --> 12/dec/2014 time --> 05:45:10
any appreciated.
you can use gsub create space between date , time , use create 2 columns read.table
read.table(text=gsub('^\\[([^:]+):(.*)+\\]', '\\1 \\2', a), sep="", col.names=c('date', 'time')) # date time # 1 12/dec/2014 05:45:10 or can use lubridate convert 'posixct' class
library(lubridate) a1 <- dmy_hms(a) a1 #[1] "2014-12-12 05:45:10 utc" if need 2 columns specified format
d1 <- data.frame(date= format(a1, '%d/%m/%y'), time=format(a1, '%h:%m:%s')) data
<- "[12/dec/2014:05:45:10]" 
Comments
Post a Comment