title: Using coefficient of variation in aggregate
body: <p>I have a data frame with 50000 rows and 200 columns. There are duplicate rows in the data and I want to aggregate the data by choosing the row with maximum coefficient of variation among the duplicates using aggregate function in R. With aggregate I can use &quot;mean&quot;, &quot;sum&quot; by default but not coefficient variation.</p>
  <p>For example</p>
  <pre><code>aggregate(data, as.columnname, FUN=mean)
  </code></pre>
  <p>Works fine.</p>
  <p>I have a custom function for calculating coefficient of variation but not sure how to use it with aggregate.</p>
  <pre><code>co.var &lt;- function(x)
  (
   100*sd(x)/mean(x)
  )
  </code></pre>
  <p>I have tried</p>
  <pre><code>aggregate(data, as.columnname, function (x) max (co.var (x, data[index (x),])
  </code></pre>
  <p>but it is giving an error as object x is not found.</p>