I have the following data-frame :
id cluster username 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
1 268672 Type 1 Vlaam 0 0 0 0 0 0 5896 18976 13552 20508 106939
2 351003 Type 2 WikiCleanerBot 0 0 0 0 0 0 0 17049 8468 22834 7470
2012 2013 2014 2015 2016
1 83874 97447 59677 88661 41133
2 11219 83245 28015 40464 25053
I need to create a last variable, telling me what variable in the 2001, 2002... 2016 series contains, for each row, the max of the serie. I write this code :
cluster$yearMod <- apply(cluster,1,function(x) {
years <- x[4:19]
as.numeric(names(years)[match(max(years),years)])
})
But this gave me :
[1] 2015 2015
Which is absolutely not the correct value, which was 2011 and 2013.
Can you help me ?