0

I'm trying to obtain the three largest number in a vector, with R. With function max() I can get the first one, is there any function that I can choose the number of values that I want?

For example: vector <- c(100,215,200,180,300,500,130) max(vector)

This will returne 500, I want something that returns: 500, 300, 215.

I've tried

pmax(vector,3)

1 Answers1

0

you can use the tail function to get the last three elements of the sorted vector.

Example:

largest_three <- tail(sort(vector), 3)
Aztec619
  • 37
  • 4