Categories: r, dataset, max

How to find the highest number of a column and print two columns of that row in R?

1 answer

How do get the highest value of column2 and print column1 and column2 of that row?

Column1 Column2 test1    2 test2    9 test3    3 test5    4.5 

So, how do I print the second row since column 2 has the highest value? Remember that there are more columns in the data set but I don't wanna print them all.

EDIT: Already tried getting the highest value of that column but I would like to print two columns of that row (not all columns).

Tried:

subset(df1, Column2 == max(Column2)) 

All answers to this question, which has the identifier 61239097

The best answer:

We can use slice - returns the first row where the max value is found

library(dplyr) df1 %>%   select(Column1, Column2) %>%   slice(which.max(Column2)) 

Or with subset from base R - returns all rows where the max value is present

subset(df1, Column2 == max(Column2), select = c(Column1, Column2)) 

Or with which.max - returns the first row where the max value is found

df1[which.max(df1$Column2),c("Column1", "Column2"), drop = FALSE] 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data