0

Essentially, I just need to drop the extra info provided by the day and month, and only retain the year. My data is in the form of dd/mm/yyyy (so, 20/11/2001 for example) and I want to just retain the yyyy (so 2001).

This question and answer: R: How to remove the day from a date? have been somewhat helpful, but I have thousands of individual dates and so copying in the exact dates I need to change isn't going to work. Does anyone have any idea how I can do this??

1 Answers1

1

Convert to date class, then extract year using format:

format(as.Date(df1$Date, format="%d/%m/%Y"),"%Y")
zx8754
  • 52,746
  • 12
  • 114
  • 209