lea
lea

Reputation: 143

How to convert a character column to datetime in R

I have a chr column in the following format and need to convert it into datetime in R, keeping the same format. How do I do it?

ts='10-MAR-21 08.07.14 PM'

Upvotes: 1

Views: 2058

Answers (1)

TarJae
TarJae

Reputation: 78917

As suggested by akrun. You can use dmy_hms function from lubridate package. Here is an example.

library(lubridate)
library(dplyr)

df1 <- df %>% 
  mutate(x = dmy_hms(x))

data:

df <- data.frame(x="10-MAR-21 08.07.14 PM")

Upvotes: 2

Related Questions