For some time now, you can also only rely on the data.table
package and its IDate
class plus associated functions (Check ?as.IDate()
). So, no need to additionally install lubridate
.
require(data.table)
a <- c("01/01/2009", "01/01/2010" , "01/01/2011")
year(as.IDate(a, '%d/%m/%Y')) # all data.table functions