My data frame has 2 columns with several hundred rows : Product Name : Describes the product sold, character & Delivery timeline : Describes when was product was delivered 21-04-2017 10:00:00, Character. I need to split the Delivery timeline column into two columns:- Date : to contain DD-MM-YYYY , date format Time : hr:mm:ss, time format. This has to be done for all rows of the columns. Can someone help with exact commands, I did try but not able to achieve the derived columns.
Asked
Active
Viewed 76 times
-5
-
3Please you should include a reproducible example together with some data, in order to help the readers. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – George Sotiropoulos Dec 22 '17 at 23:31
-
2I would recommend against splitting your column. R does not handle times very well. I would use the as.POSIXct function and convert the character strings to a date/time object which can then be formatted for output or used in further analysis. – Dave2e Dec 23 '17 at 01:46
1 Answers
0
dat=data.frame(time=rep(Sys.time(),10)+10001:10010,stringsAsFactors = F)
dat
time
1 2017-12-22 18:31:27
2 2017-12-22 18:31:28
3 2017-12-22 18:31:29
4 2017-12-22 18:31:30
5 2017-12-22 18:31:31
6 2017-12-22 18:31:32
7 2017-12-22 18:31:33
8 2017-12-22 18:31:34
9 2017-12-22 18:31:35
10 2017-12-22 18:31:36
proto=data.frame(date=character(), time=character())
strcapture("(\\w.*)\\s(\\w.*)",as.character(A$time),proto)
date time
1 2017-12-22 18:31:27
2 2017-12-22 18:31:28
3 2017-12-22 18:31:29
4 2017-12-22 18:31:30
5 2017-12-22 18:31:31
6 2017-12-22 18:31:32
7 2017-12-22 18:31:33
8 2017-12-22 18:31:34
9 2017-12-22 18:31:35
10 2017-12-22 18:31:36

Onyambu
- 67,392
- 3
- 24
- 53