0

$ date "20141013T000000", "20141209T000000", "20150225T000000", "20141209T000000"

I have this "date" variable in R dataframe. I want to clean this variable and remove "T000000" such that "20141013T000000" shows only "20141013" so I can then convert my date variable into it's proper date format.

Thank you very much.

Brennon
  • 1
  • 3

2 Answers2

2

You don't need to remove that, you can just do the date-conversion directly and specify the existing format:

as.Date("20141013T000000", "%Y%m%dT000000")
# [1] "2014-10-13"
talat
  • 68,970
  • 21
  • 126
  • 157
2

Or a lubridate solution:

data <- "20141013T000000"
library(lubridate)
as_datetime(date)
#[1] "2014-10-13 UTC"
J_F
  • 9,956
  • 2
  • 31
  • 55