Guest User

Untitled

a guest
Oct 21st, 2019
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data