Home > Mobile >  How to format a 14-digit number (in a csvfile) into Ymd in R?
How to format a 14-digit number (in a csvfile) into Ymd in R?

Time:12-07

I have a dataset in which one column is the date. It's written like 20130314151615 how can i manipulate the whole column so that i get the year, month and day?

20130314151615 to 2013-03-14

CodePudding user response:

This should do what you wanted

as.Date( "20130314151615", format="%Y%m%d" )
[1] "2013-03-14"

CodePudding user response:

With lubridate package we can make use of as_date after defining ymd_hms:

library(lubridate)
as_date(ymd_hms(20130314151615))
[1] "2013-03-14"
  •  Tags:  
  • r
  • Related