after grouping by q, would then like to extract two max value from two different w e columns respectively
input data:
q <- c(503,503,503,503,503,503,503,503,503,503,503,503,503,510,510,510,510,510,510,510,510,510,510,510,510,525,526,526)
w <- c(56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56)
e <- c(26,26,26,26,26,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,29,30,30,30,30,33,33,33)
r <- data.frame(q,w,e, stringsAsFactors = FALSE)
Code:
r %>% group_by(q) %>% slice(which.max(w & e))
My Output:
  q     w     e
 <dbl> <dbl> <dbl>
1  503.   56.   26.
2  510.   56.   28.
3  525.   56.   33.
4  526.   56.   33.
Expected Output:
    q   w  e
1  503 56 28
2  510 56 30
3  525 56 33
4  526 56 33
would prefer to use %>% and slice command as the above code instead of finding max separately q$w q$e and then merging by q (would like to avoid merge as my actual data is large object.size ~2GB)
 
     
     
     
    