0

I have 53000 Date data-set and I want to extract only "year" from the date variable. Do you guys know how can I do this? My data are as follows:

OPN_DT_TM
18/07/2003 10:55
12/06/2004 6:00
9/06/2007 12:20
29/06/2001 16:00
6/06/2000 7:55
27/11/2006 10:15
17/11/2001 17:00
12/05/2004 22:00
16/04/2005 22:00
18/03/2005 8:40
13/06/2006 11:10
30/07/2006 12:00
16/07/2002 6:10
16/07/2002 7:15
3/09/2004 6:00
9/11/2004 15:20
25/08/2005 14:15
24/11/2001 19:10
15/04/2002 6:30
20/06/2002 6:30
17/03/2003 7:00
15/01/2005 13:00
23/03/2007 1:00
21/01/2001 10:30
,,,
Spacedman
  • 92,590
  • 12
  • 140
  • 224

1 Answers1

0

This can be achieved by converting the entries into Date format and extracting the year, for instance like this:

> format(as.Date("15/01/2005 13:00", format="%d/%m/%Y %H:%M"),"%Y")
[1] "2005"

To get in-depth knowledge about dates and times in R, please see this.

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161