Use the `partial`

argument of `sort()`

. For the second highest value:

```
n <- length(x)
sort(x,partial=n-1)[n-1]
```

### Related Contents:

- Split a vector into chunks
- Counting the number of elements with the values of x in a vector
- How to find common elements from multiple vectors?
- How to convert a list consisting of vector of different lengths to a usable data frame in R?
- How to cbind or rbind different lengths vectors without repeating the elements of the shorter vectors?
- R memory management / cannot allocate vector of size n Mb
- Test if a vector contains a given element
- Create grouping variable for consecutive sequences and split vector
- How to tell what is in one vector and not another?
- How to merge 2 vectors alternating indexes?
- Multiply rows of matrix by vector?
- Alternate, interweave or interlace two vectors
- Finding All Positions for Multiple Elements in a Vector
- How to index a vector sequence within a vector sequence
- else if(){} VS ifelse()
- Get indexes of a vector of numbers in another vector
- Convert data.frame column to a vector?
- Select every other element from a vector
- How to divide each row of a matrix by elements of a vector in R
- Count values separated by a comma in a character string
- Convert Named Character Vector to data.frame
- Reduce PDF file size of plots by filtering hidden objects
- How do keep only unique words within each string in a vector
- How to access the last value in a vector?
- Extract every nth element of a vector
- Converting two columns of a data frame to a named vector
- Append value to empty vector in R?
- List distinct values in a vector in R
- How do I map a vector of values to another vector with my own custom map in R [duplicate]
- How do I extract just the number from a named number (without the name)?
- Split delimited single value character vector
- Test for equality among all elements of a single numeric vector
- R split numeric vector at position
- Extract a column from a data.table as a vector, by position
- Find start and end positions/indices of runs/consecutive values
- Concatenate rows of a data frame
- Convert a dataframe to a vector (by rows)
- Unlist a data frame by rows, not columns
- How to reverse order a vector?
- “for” loop only adds the final ggplot layer
- Pass a vector of variables into lm() formula
- How to subtract/add days from/to a date?
- How to add code folding to output chunks in rmarkdown html documents
- ggplot combining two plots from different data.frames
- How to display only integer values on an axis using ggplot2
- R self reference
- if – else if – else statement and brackets
- How can I force a line break in rmarkdown’s title?
- Add a column with count of NAs and Mean
- Moving color key in R heatmap.2 (function of gplots package)