finding the max of a series of variables in a data-frame
<p>I have the following data-frame :</p>

<pre><code>      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
</code></pre>

<p>I need to create a last variable, telling me what variable in the 2001, 2002... 2016 series contains, for each row, the <strong>max</strong> of the serie. I write this code :</p>

<pre><code>cluster$yearMod &lt;- apply(cluster,1,function(x) {
  years &lt;- x[4:19]
  as.numeric(names(years)[match(max(years),years)])
})
</code></pre>

<p>But this gave me :</p>

<pre><code>[1] 2015 2015
</code></pre>

<p>Which is absolutely not the correct value, which was 2011 and 2013.</p>

<p>Can you help me ?</p>