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,438
  • 68
  • 55
  • 126
Jack Armstrong
  • 1,031
  • 3
  • 21
  • 44

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
  • 62,170
  • 17
  • 162
  • 226