Reputation: 23
When I use the "as.Date" command in r it returns Na as a result, I have tried different things like transforming it to POSIXt format, changing the date format with % and even using the "paste" command, but it doesn't work.
#The format I want to have:
format(Sys.Date(), "%B de %Y")
[1] "December de 2022"
#Example
date="noviembre de 2022"
#Attempt 1:
date2 <- strptime(date, format = "%B de %Y")
date3 <- as.Date(date2,format="%B de %Y")
date3
[1] NA
#Attempt 2:
date2 <- as.Date(paste(1, gsub("de ", "", date)), format = "%d %B %Y")
date2
[1] NA
#Attempt 3:
date2 <- as.Date(date,format="%B de %Y")
date2
[1] NA
#Attempt 4:
a <- as.character("noviembre de 2022")
pos_dt <- strptime(a, format = "%B de %Y")
b <- as.Date(pos_dt, format = "%B de %Y")
print(a)
[1] NA
print(b)
[1] NA
I don't know what other option I could try or how I could solve the problem. I just need r to read me the date format like I have in the example.
Thanks for the help
Upvotes: 0
Views: 22