To calculate the mean with a data.table in R, you can use the data.table package's aggregate function. Here's an example:
230 chars11 lines
In the first example, dt[, mean(x)] calculates the mean of the x column in the dt data.table.
In the second example, dt[, mean(y), by = x] calculates the mean of the y column, grouped by the x column. This creates a new data.table that has one row for each unique value in the x column, along with the mean of the y column for that value of x.
gistlibby LogSnag