[R] Need hep for converting date data in POSIXct

arun smartpink111 at yahoo.com
Mon Jul 8 03:01:42 CEST 2013


Hi,
I am not sure how your dataset looks like.  If it is like the one below: (otherwise, please provide a reproducible example using ?dput())

dat1<- read.table(text="
datetime
10/02/2010
02:30
11/02/2010
04:00
14/02/2010
06:30
",sep="",header=TRUE,stringsAsFactors=FALSE)

lst1<-split(dat1,(seq_along(dat1$datetime)-1)%%2+1)
 dat2<- data.frame(datetime=as.POSIXct(paste(lst1[[1]][,1],lst1[[2]][,1]),format="%d/%m/%Y %H:%M"))
 str(dat2)
#'data.frame':    3 obs. of  1 variable:
# $ datetime: POSIXct, format: "2010-02-10 02:30:00" "2010-02-11 04:00:00" ...
 dat2
#             datetime
#1 2010-02-10 02:30:00
#2 2010-02-11 04:00:00
#3 2010-02-14 06:30:00


#or
data.frame(datetime=as.POSIXct(paste(dat1[seq(1,nrow(dat1),by=2),1],  dat1[seq(2,nrow(dat1),by=2),1]),format="%d/%m/%Y %H:%M"))
#             datetime
#1 2010-02-10 02:30:00
#2 2010-02-11 04:00:00
#3 2010-02-14 06:30:00



A.K.



Hey everybody, 

I am a new user of R software. I don't know how I can merge two rows in 
one. In fact, I have one row with the date(dd/mm/yyyy) and another with the 
time (hh:mm) and I would like to get one row with date time in order to 
convert to POSIXct. How can I do it??



More information about the R-help mailing list