I am trying to convert a column in R that is a factor to a date time. When I use lubridate, my values are changed to POSIXCt, but the times are dropped. Is there a solution that I am not seeing?
Import Data:
transaction_march_raw <- read.csv(file = "myfile.csv")
transaction_march <- data.frame(transaction_march_raw, stringsAsFactors = FALSE)
Clean transactions:
transaction_march <- transaction_march_raw %>%
select(ACT_TRANS_DATE) %>%
clean_names()
str(transaction_march)
'data.frame': 373143 obs. of 1 variable:
$ act_trans_date: Factor w/ 38543 levels "2/1/20 0:00",..: 1 1 1 1 1 1 1 1 1 1 ...
head(transaction_march)
act_trans_date
1 2/1/20 0:00
2 2/1/20 0:00
3 2/1/20 0:00
4 2/1/20 0:00
5 2/1/20 0:00
6 2/1/20 0:00
transaction_march$act_trans_date <- mdy_hm(transaction_march$act_trans_date)
str(transaction_march)
'data.frame': 373143 obs. of 1 variable:
$ act_trans_date: POSIXct, format: "2020-02-01" "2020-02-01" "2020-02-01" "2020-02-01" ...
head(transaction_march)
act_trans_date
1 2020-02-01
2 2020-02-01
3 2020-02-01
4 2020-02-01
5 2020-02-01
6 2020-02-01