0

Take any random dataset:

data = rnorm(100)

I want to get a list of the largest 5% of values in this data. If I try:

quantile(data, .95)

...then I get the single value at the 95th percentile. If I try:

quantile(data, probs=c(1, .95))

...then I get only two values: the largest value in the dataset and the value at the 95th percentile. If I try:

quantile(data, 1 - .95)

...then I get the single value at the 5th percentile. If I try:

quantile(data, >.95)

...then I get a syntax error message.

How do I get a list of all values within a given quantile range? (In this case how do I get a list of all values that fall between the 100th and 95th percentiles?)

bubbalouie
  • 643
  • 3
  • 10
  • 18

1 Answers1

2

Use basic subsetting:

data[data>quantile(data, .95)]

Technically, this is a "numeric vector" in R and not a "list", which is a different data type, but I assume it's what you want.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453