[R] modify timestemp

arun smartpink111 at yahoo.com
Wed Jul 3 23:57:20 CEST 2013


Hi,
May be this helps:

dat1# dataset
dat1[,2]<-gsub("\\d+$","00",dat1[,2])
 dat1
#         Date     Time
#1  01/01/2013 00:09:00
#2  01/02/2013 00:10:00
#3  01/03/2013 00:11:00
#4  01/04/2013 00:12:00
#5  01/05/2013 00:13:00
#6  01/06/2013 00:15:00
#7  01/07/2013 00:16:00
#8  01/08/2013 00:17:00
#9  01/09/2013 00:18:00
#10 01/10/2013 00:19:00
A.K.


Hey All, 

I want to standardize my timestamp which is formatted as hh:mm:ss 

 My data looks like this: 

     Date     Time 
01/01/2013 00:09:01 
01/02/2013 00:10:14 
01/03/2013 00:11:27 
01/04/2013 00:12:40 
01/05/2013 00:13:53 
01/06/2013 00:15:06 
01/07/2013 00:16:19 
01/08/2013 00:17:32 
01/09/2013 00:18:45 
01/10/2013 00:19:58 

Dataset <- structure(list(Date = c("01/01/2013", "01/02/2013", 
"01/03/2013", 
"01/04/2013", "01/05/2013", "01/06/2013", "01/07/2013", "01/08/2013", 
"01/09/2013", "01/10/2013"), Time = c("00:09:01", "00:10:14", 
"00:11:27", "00:12:40", "00:13:53", "00:15:06", "00:16:19", "00:17:32", 
"00:18:45", "00:19:58")), .Names = c("Date", "Time"), class = "data.frame", 
row.names = c(NA, 
-10L)) 

I would like to change all the records in "Time" column uniformed as 
hh:mm:00, then the output would be this: 

Date     Time 
01/01/2013 00:09:00 
01/02/2013 00:10:00 
01/03/2013 00:11:00 
01/04/2013 00:12:00 
01/05/2013 00:13:00 
01/06/2013 00:15:00 
01/07/2013 00:16:00 
01/08/2013 00:17:00 
01/09/2013 00:18:00 
01/10/2013 00:19:00 

Thanks for your help!



More information about the R-help mailing list