Use the partial
argument of sort()
. For the second highest value:
n <- length(x)
sort(x,partial=n-1)[n-1]
More Related Contents:
- Test if a vector contains a given element
- Counting the number of elements with the values of x in a vector
- 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?
- How to merge 2 vectors alternating indexes?
- Multiply rows of matrix by vector?
- How to divide each row of a matrix by elements of a vector in R
- Alternate, interweave or interlace two vectors
- How to index a vector sequence within a vector sequence
- Finding All Positions for Multiple Elements in a Vector
- Get indexes of a vector of numbers in another vector
- Convert data.frame column to a vector?
- Convert Named Character Vector to data.frame
- Reduce PDF file size of plots by filtering hidden objects
- Converting two columns of a data frame to a named vector
- Append value to empty vector in R?
- How do keep only unique words within each string in a vector
- Test for equality among all elements of a single numeric vector
- List distinct values in a vector in R
- calculating mean for every n values from a vector
- Find start and end positions/indices of runs/consecutive values
- Unlist a data frame by rows, not columns
- Split delimited single value character vector
- R split numeric vector at position
- Extract a column from a data.table as a vector, by position
- Concatenate rows of a data frame
- How to return 5 topmost values from vector in R?
- How to reverse order a vector?
- propagating data within a vector
- How do you create vectors with specific intervals in R?