Evaluation error: character string is not in a standard unambiguous format

dplyr
tidyverse
rstudio

#1

Hi all,
I am working with a date column and getting the following error,

Evaluation error: character string is not in a standard unambiguous format.

I am going to reprex my code, so that you can assume what wrong I have done.

library(readr)

setwd("E:\\Buisness Analytics\\R\\PRACTISE\\Relevancy Accuracy Test")

nakamura <- read.csv("For R.csv")

head(nakamura$AddedDate,10)
#>  [1] 1/3/18 12:28 AM 1/3/18 12:28 AM 1/3/18 12:28 AM 1/3/18 12:28 AM
#>  [5] 1/3/18 12:28 AM 1/3/18 12:28 AM 1/3/18 12:28 AM 1/3/18 12:28 AM
#>  [9] 1/3/18 12:28 AM 1/3/18 12:28 AM
#> 1199 Levels: 1/10/18 1:32 AM 1/10/18 1:36 AM ... 3/9/18 12:25 AM

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:lubridate':
#> 
#>     intersect, setdiff, union
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

class(nakamura$AddedDate)
#> [1] "factor"
nakamura$AddedDate <- as.Date(nakamura$AddedDate)

ambrose <- nakamura %>%
  select(LoyaltyCardNumber,OfferCode,AddedDate) %>%
  filter(AddedDate >='01/10/18' & AddedDate <='01/16/18')
#> Error in filter_impl(.data, quo): Evaluation error: character string is not in a standard unambiguous format.

When I am going to filter between two days (01/10/18 and 01/16/18), it showing me the error. But when i am filtering between 01/03/18 and 01/09/18 these two dates. It is showing me the perfect output.
I have tried many ways to solve this error, such as,

nakamura$AddedDate <- as.Date(nakamura$AddedDate,format= "%m.%d.%y")
nakamura$AddedDate <- as.POSIXct(as.numeric(as.character(nakamura$AddedDate)),origin = "1970-01-01")
nakamura$AddedDate <- as.POSIXct("1/3/18 12:28 AM")

By anytime package

library(anytime)

nakamura$AddedDate <- anydate(nakamura$AddedDate)

But, nothing have solved my error.
Can you guys help me for that?
Please help me to solve this problem.Any suggestion is really appreciable.

Sincerely,
snandy2011


#2

You can parse your date and time with readr this way:

library(readr)

parse_datetime(nakamura$AddedDate, "%m/%d/%y %I:%M %p")

After this, you could try your code again and see if this time it works without error message.


#3

Side note: this is not a reprex since you are uploading data we do not have access to. It would be better to create a little code sample of your data that we could copy-paste easily.

This way, I could have tested your full code. But as things are, I would have to copy and transform the output of your head(nakamura$AddedDate,10) (which is not difficult but takes extra time and effort).