My question is pretty simple. I would like to cut off 5% of the highest and lowest values. Here is my sample data set.

x = rnorm(100)
x_sorted = sort(x, decreasing = F)

I tried to apply the trim function. But unfortunately this function just works if I want to generate trimmed means.

1 Answers

3
Ronak Shah On Best Solutions

We can use quantile to calculate value at 5% and 95% of x and then subset the values which lie between them.

x[x > quantile(x, 0.05) & x < quantile(x, 0.95)]