Get NA when trying to do the date

Amendments$Proposed <- as.Date(Amendments$Proposed, '%B/%d/%Y')
Amendments$Proposed

I am doing this to try and enter the date in date format but it is coming up as this:

[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

There are no slashes in the dates, so you should not use them in the definition of the format within as.Date(). Use spaces and a comma as in your data. For example

as.Date("September 25, 1789", format = "%B %d, %Y")
1 Like

Dates entered as literal character strings, such as "December 18, 1971" are not the same thing as date or datetime objects.

The lubridate package has convenient functions to transform strings to date objects.

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
the_date <- "December 18, 1917"
mdy(the_date) -> result
str(result)
#>  Date[1:1], format: "1917-12-18"

Created on 2020-09-28 by the reprex package (v0.3.0.9001)

@sarahharves you posted here before with screenshots instead of properly accessible code or ideally a reprex. As a newcomer to the forum you were helped out anyway, but you did not seem to take notice of the requests by those who were helping you.

This isn't your first time here so you should be aware of the importance of providing better material to people to work with. You are, after all, asking people to give up their free time to help you, so it makes sense that you should help them to help you.

2 Likes

This topic was automatically closed 21 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.