Brennon
Brennon

Reputation: 1

Removing character strings in date in R

$ 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.

Upvotes: 0

Views: 1332

Answers (2)

J_F
J_F

Reputation: 10352

Or a lubridate solution:

data <- "20141013T000000"
library(lubridate)
as_datetime(date)
#[1] "2014-10-13 UTC"

Upvotes: 2

talat
talat

Reputation: 70266

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"

Upvotes: 2

Related Questions