Hello! I am trying to bring date and time data into RStudio and create a datetime column. I seem to be having trouble when I try and use lubridate functions; I receive warning messages that all formats failed to parse. The datetime column is created but all values are "na". Even under "#Parse Date column", I had tried to use mdy() opposed to as.Date(), but mdy() would not work. Please see reprex below. Thank you!
library("tidyverse") library("lubridate") #> #> Attaching package: 'lubridate' #> The following objects are masked from 'package:base': #> #> date, intersect, setdiff, union #Create sample dataset MV.71 <- data.frame(stringsAsFactors = FALSE, DATE = c(NA, NA, "10/15/2020", "10/15/2020", "10/15/2020", "10/15/2020"), TIME = structure(c(NA, NA, 48600, 50400, 52200, 54000), class = c("hms", "difftime"), units = "secs")) #Parse DATE column MV.71 <- MV.71 %>% mutate(DATE = as.Date(DATE, tz = "America/New_York", format = "%m/%d/%Y")) #Create datetime_string as character from DATE and TIME #Create datetime from datetime_string MV.71 <- MV.71 %>% mutate( datetime_string = paste(DATE, TIME, sep = "_"), datetime = lubridate::mdy_hms(datetime_string, tz = "America/New_York")) #> Warning: Problem with `mutate()` input `datetime`. #> i All formats failed to parse. No formats found. #> i Input `datetime` is `lubridate::mdy_hms(datetime_string, tz = "America/New_York")`. #> Warning: All formats failed to parse. No formats found.
Created on 2021-01-08 by the reprex package (v0.3.0)