R do.call() with rbind(): operate on data frame

15 Oct 2017

Useful to aggregate based on more than one columns. For example to select the start that has the smallest end:

inData_smallest <- do.call(rbind, by(inData, inData$start, function(x) x[which.min(x$end),]))

Or to select the smallest start with biggest end:

inData_smallest <- do.call(rbind, by(tmpDF, tmpDF$gene_id, function(x) c(min(x$start), max(x$end))))
[ R  function  ]