Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. maxN <- function(x, N=2, decreasing = FALSE){
  2. len <- length(x)
  3. if(N>len){
  4. warning('N greater than length(x). Setting N=length(x)')
  5. N <- length(x)
  6. }
  7. if (decreasing == FALSE) {
  8. sort(x,partial=len-N+1)[len-N+1]
  9. } else {
  10. -sort(-x,partial=len-N+1)[len-N+1]
  11. }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement