I have data that looks like this:
require(data.table)
DT <- data.table(x=c(19,19,19,21,21,19,19,22,22,22),
y=c(53,54,55,32,44,45,49,56,57,58))
I would like to search by x and calculate the means for y. However, when used.
DT[, .(my=mean(y)), by=.(x)]
I get generic tools for matching x values. I would like to search by x, and every time x changes, I would like to calculate a new value. For the given example, the output will look as follows:
DTans <- data.table(x=c(19,21,19,22),
my=c(54,38,47,57))