I am calculating the Tukey outlier detection algorythm on a data set of prices.
The thing is that I need it to be calculated by group (another variable included in the same data set), which works perfectly fine with the aggregate
command up until I need to calculate a mean using only the data between percentile 5 to the median and one using only the data from the median to percentile 95.
As far as I know, the command goes this way: aggregate(doc$
x, by=list(doc$
group), FUN=mean, trim = 0.05)
, if the mean was trimmed symmetrically taking the upper and lower 5% (total 10%) from the data before printing the result.
I don't know how to go through the next steps where I need to calculate the upper and lower mean taking the median as a division point, still keeping the upper and lower 5% off.
medlow <- aggregate(doc1$`rp`, by=list(doc1$`Código Artículo`), FUN=mean,trim =c(0.05,0.5))
medup <- aggregate(doc1$`rp`, by=list(doc1$`Código Artículo`), FUN=mean,trim =c(0.5,0.95))
medtrunc <- aggregate(doc1$`rp`, by=list(doc1$`Código Artículo`), FUN=mean,trim = 0.05)
I expect the output to be the number I need for each group, but it goes
Error in mean.default(X[[i]], ...) : 'trim' must be numeric of length one.