Description Usage Arguments Value Examples
A function to find the top nth-highest value in a vector From kohske on StackOverflow http://stackoverflow.com/questions/10296866/finding-the-column-number-and-value-the-of-second-highest-value-in-a-row/10297025#10297025
1 | maxn(n)
|
n |
vector of numbers |
top nth value
1 2 3 4 5 6 7 8 9 10 11 12 | mydata <- c(6, 10, 2, 21, 13, 20, 4, 12)
secondhighest <- mydata[maxn(2)(mydata)]
# or define function for second highest:
max2 <- maxn(2)
secondhighest <- mydata[max2(mydata)]
# To find second-highest number in each row in a dataframe:
## Not run:
apply(df, 1, function(x)x[maxn(2)(x)])
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.