0

I thought this would be easy but I'm hitting a wall. Very simply, I'd like to return the value in V2 based on the max value in V1. If there's a tie in the V1 max values it would "randomly" pick one and return the V2 value.

Any assistance would be greatly appreciated!

set.seed(1)
DF <- matrix(sample(1:40,40),ncol=2,nrow=20)
DF <- as.data.frame.matrix(DF)
View(DF)
rawr
  • 20,481
  • 4
  • 44
  • 78
Atwp67
  • 307
  • 5
  • 21
  • 1
    `DF$V1[which.max(DF$V2)]` – G5W Feb 10 '17 at 17:11
  • 1
    I would say `DF$V1[max.col(t(DF$V2))]` instead since `max.col` has a ties argument (the default is random) but `which.max` does not; [similar question/answer](http://stackoverflow.com/questions/15630032/which-max-ties-method-in-r) – rawr Feb 10 '17 at 17:15
  • The example does not have the desired output that should result from `DF` – Pierre L Feb 10 '17 at 17:21
  • @rawr Thanks to everyone responding back! Because of possible ties I'll try the max.col code. – Atwp67 Feb 10 '17 at 17:23

0 Answers0