title: How to get maximum value from a column in a data.frame and get ALL records
body: <p>I have a data.frame and I wish to get the row that contains the maximum value for the given column <code>Total</code> </p>
  
  <pre><code>Txn_date  Cust_no   Acct_no cust_type Credit Debit Total
  09DEC2013   17382 601298644         I   1500     0  1500
  16DEC2013   17382 601298644         I    500     0   500
  17DEC2013   17382 601298644         I      0    60    60
  18DEC2013   17382 601298644         I      0   200   200
  19DEC2013   17382 601298644         I   1500     0  1500
  20DEC2013   17382 601298644         I      0    60    60
  20DEC2013   17382 601298644         I      0   103   103
  30DEC2013   17382 601298644         I    500     0   500
  </code></pre>
  
  <p>So, I wrote a simple SQL query, to be parsed using <code>sqldf()</code> as follows :</p>
  
  <pre><code>s1&lt;-paste("SELECT Txn_date, Cust_no,Credit,Debit,Total,max(Total) as 'MaxTxnAmt' FROM sample GROUP BY Cust_no")
  sample_t1&lt;-sqldf(s1)
  </code></pre>
  
  <p>And that gives me </p>
  
  <pre><code>Txn_date Cust_no   Acct_no cust_type Credit Debit Total
  09DEC2013   17382 601298644         I   1500     0  1500
  </code></pre>
  
  <p>I get the exact output as shown above if I am using <code>base - R</code> functions :</p>
  
  <pre><code>sample_t1&lt;-do.call(rbind,
          lapply(split(sample,sample$Cust_no),
                 function(data) data[which.max(data$Total),]))
  </code></pre>
  
  <p>I wish to know, how do I get ALL the rows from the table <code>sample</code> that have the maximum value for the column <code>Total</code>.</p>
  
  <p>Desired output :</p>
  
  <pre><code>Txn_date Cust_no   Acct_no cust_type Credit Debit Total
  09DEC2013   17382 601298644         I   1500     0  1500
  19DEC2013   17382 601298644         I   1500     0  1500
  </code></pre>
  
  <hr>
  
  <p>Sample data :</p>
  
  <pre><code>sample &lt;- structure(list(Txn_date = c("09DEC2013", "16DEC2013", "17DEC2013", 
  "18DEC2013", "19DEC2013", "20DEC2013", "20DEC2013", "30DEC2013"
  ), Cust_no = c(17382L, 17382L, 17382L, 17382L, 17382L, 17382L, 
  17382L, 17382L), Acct_no = c("601298644", "601298644", "601298644", 
  "601298644", "601298644", "601298644", "601298644", "601298644"
  ), cust_type = c("I", "I", "I", "I", "I", "I", "I", "I"), Credit = c(1500, 
  500, 0, 0, 1500, 0, 0, 500), Debit = c(0, 0, 60, 200, 0, 60, 
  103, 0), Total = c(1500, 500, 60, 200, 1500, 60, 103, 500)), .Names = c("Txn_date", 
  "Cust_no", "Acct_no", "cust_type", "Credit", "Debit", "Total"
  ), row.names = c(16303L, 29153L, 31174L, 33179L, 35388L, 38750L, 
  38751L, 53052L), class = "data.frame")
  </code></pre>