I'm trying to select rows in a dataframe, where value in X1 is the maximum value across all rows.
X1 <- c(0.7,0.6,0.2,0.5,0.2,0.1,0.1,0.1,0.3,0.2)
X2 <- c(0.1,0.2,0.6,0.3,0.7,0.8,0.1,0.1,0.2,0.7)
X3 <- c(0.1,0.2,0.8,0.2,0.2,0.1,0.4,0.2,0.1,0.2)
df <- data.frame(X1,X2,X3)
I can see from visualizing the data that X1 is the maximum for rows 1,2,4,9. I tried writing a something like this with a loop but no success.
df[ df$X1[i] == max(df[ [i] ,] ) , ]
Does it need to be done by loop, or can it be done using a function? Any help is greatly appreciated. Thanks