user2350622
user2350622

Reputation: 77

How to convert date format in R

My data contains a variable which recorded the date like "Wednesday 01/01/86". I want to drop the days like "Wednesday" and convert "01/01/86" into the format "1986-01-01".

I tried as.Date(myData$DATE) but I got an error message: character string is not in a standard unambiguous format. I assume this is due to the character Wednesday?

Upvotes: 0

Views: 155

Answers (1)

BrodieG
BrodieG

Reputation: 52687

You have to tell as.Date what format your input is in:

as.Date("Wednesday 01/01/86", format="%A %m/%d/%y")
# "1986-01-01"

See docs for strptime for more details.

Upvotes: 1

Related Questions