Suppose I want to calculate the trimmed mean of the following data:
set.seed(1)
s<-rnorm(10,100,20)
#[1] 87.47092 103.67287 83.28743 131.90562 106.59016 83.59063 109.74858 114.76649 111.51563 93.89223
I can use the mean function with a trim parameter of, say, 0.05, which gives a trimmed mean of 102.6441.
mean(s, trim = 0.05)
# 102.6441
However, if I decide to trim the mean by manually using only data that lies between the 0.05 quantile and the 0.95 quantile, I get a trimmed mean of 101.4059
mean(s[which(s <= quantile(s, 0.95) & s >= quantile(s, 0.05))])
# 101.4059
Can anyone explain this behaviour? What does the trim parameter in the mean function actually do?