I have the following vector with dates in mdY
or excel_numeric
format from a dataframe that I've imported from excel.
data <- structure(list(Date = c("12/31/1996", "35462", "35490", "35582",
"35612", "35643", "35674", "35704", "1/13/1997", "1/14/1997",
"1/15/1997")), row.names = c(NA, -11L), class = c("tbl_df", "tbl",
"data.frame"))
I've tried to follow this solution to convert my vector into R recognised dates, however when I try to run the last step to convert the dates that are excel numeric
format using replace
, I get the following error. Is there any way to address this and clean my dates into date format?
library(tidyverse)
library(lubridate)
data_fixed <- data %>%
mutate(Date = parse_date_time(Date, c('mdY')))
replace(data_fixed, is.na(data_fixed), as.Date(as.integer(data[is.na(data_fixed)]), origin = "1899-12-30"))
Error in `[<-`:
! Subscript `list` is a matrix, the data `values` must have size 1.
Run `rlang::last_trace()` to see where the error occurred.