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.

enter image description here

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

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -