As title suggested , I have a query to access the row value (not the index and not the entire row) corresponding to max value of a column.
FOR EX: I have below data set(results):
Name subject marks
sam maths 88
paul science 79
tom social 66
james english 78
richard maths 83
Need help for following:
- How to write command to retrieve row value ("sam") corresponding to max col value of marks (88)?
I was able to get the max value of marks column using the below command:
max(results$marks, na.rm = TRUE)
However, when I assign it to a variable to see who topped the exam, I get only the header names no the value as sam.
top_scorer<- results$Name[which.max(results$marks, na.rm = TRUEr)]
- How to write a command to find out which person comes second on the list in terms of marks?
Please help. I am beginner in R programming.