-2

activity$ActivityDate = as.POSIXct(activity$ActivityDate, format="%d/%m/%y", tz=Sys.timezone()) returns NA in ActivityDate and Date columns in R

activity$ActivityDate = as.POSIXct(activity$ActivityDate, format="%d/%m/%y", tz=Sys.timezone()) ends up with NA in ActivityDate column in R

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
SHEETHAL
  • 1
  • 1

1 Answers1

1

I can only guess what you would like to achieve based on your question title - it would help if you could include a minimal reproducible example and some prose describing your problem.

It seems that lubridate's parsing functions might do what you need:

ActivityDate <-  c("07/31/2022", "07-31-2022")
lubridate::mdy(ActivityDate)
#> [1] "2022-07-31" "2022-07-31"

Created on 2022-12-21 with reprex v2.0.2

dufei
  • 2,166
  • 1
  • 7
  • 18