I have this date in string format
v<- "31/06/23"
It's 31 of June of 2023
class(v)
[1] "character"
The dmy() lubridate function doesn't work
dmy(v)
[1] NA
Warning message:
1 failed to parse.
Also other codes
as.Date(v, format = "%d/%m/%Y")
[1] NA
If I try as.Date () function it returns 31 as year
as.Date(v)
[1] "0031-06-23"
How can I do?
Wrong: Ah, Y2K. Date conversion handles the two-digit year. @Rolando has it right, too many days for June. I leave the post standing just in case anyone needs the regex
.
v <- "31/06/23"
repaired <- gsub("(\\d{2}/\\d{2}/)(\\d{2})", "\\120\\2", v)
repaired
#> [1] "31/06/2023"
Created on 2023-08-31 with reprex v2.0.2
Might it be because 31/06/23 is not a valid date?
Does 30/06/23 work?
Yeah, this is it! It works. Thanks.
system
Closed
September 7, 2023, 8:07pm
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.