title: How to get the date of maximum values of rainfall in programming language R
body: <p>I have a data frame with an year of daily values of rainfall (complete dates in column 1,months in column 2, rainfall in column 3). I am trying to calculate monthly maximum rainfall and I also would like to know the date when the maximum occurred.</p>
  
  <p>I tried the following code:</p>
  
  <pre><code>for (imonth in 1:12) {
      month &lt;- which(data[,2]==imonth)
      monthly_max[imonth] &lt;- max(data[month,3])
      maxi[imonth] &lt;- which.max(data[month,3])
  }
  tabela &lt;- cbind(monthly_max, maxi)
  write.table(tabela, col.names=TRUE, row.names=TRUE, append=FALSE, sep="\t")
  </code></pre>
  
  <p>The monthly maximum worked perfectly but the which.max function is not working correctly. Is giving me rows that do not correspond to the maximum values of rainfall. Can anybody tell me why or maybe suggest a better way of doing this? </p>
  
  <p>Thank you for helping!</p>