Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting two columns of date and time data to one

Tags:

r

I have a simple data frame:

D <- c("2012/12/14", "2012/12/14")
Time <- c("18:40:37", "18:40:48")
df1 <- data.frame(D, Time)

I wish to combine the two columns of date and time information into one, preferable in the format of day, month, year, time.

How would I go about doing this?

like image 237
KT_1 Avatar asked Jan 16 '13 13:01

KT_1


People also ask

How do I combine date and time columns in pandas?

Pandas Combine() Function combine() function which allows us to take a date and time string values and combine them to a single Pandas timestamp object. The function accepts two main parameters: Date – refers to the datetime. date object denoting the date string.

How do I concatenate date and time to text in Excel?

To combine the date and time columns into one column, the following formula can help you: 1. Enter this formula: =concatenate(text(A2,"mm/dd/yyyy")&" "&text(B2,"hh:mm:ss")) into a blank cell where you want to put the combined result, then press Enter key to get the first combined cell.


1 Answers

R> within(df1, { timestamp=format(as.POSIXct(paste(D, Time)), "%d/%m/%Y %H:%M:%S") })

           D     Time           timestamp
1 2012/12/14 18:40:37 14/12/2012 18:40:37
2 2012/12/14 18:40:48 14/12/2012 18:40:48
like image 113
rcs Avatar answered Oct 08 '22 09:10

rcs