2

I have a table, tble from a dataframe, dfas below:

tble<-table(df$eye_color)

So it produces values as follows:

tble
    Brown        Black      Green      Blue
     7          10          2           1 

I want to define a variable that returns the row name with the max value in the table. For this example, it would be Black.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jack Armstrong
  • 1,182
  • 4
  • 26
  • 59

1 Answers1

3

Strange, I did not find a duplicate when I search "[r] max of a table". But I remember seeing something similar.

names(tble)[which.max(tble)]
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248