Getting column name which holds a max value within a row of a matrix holding a separate max value within an array

This should do it - if I understand correctly:

Q <- array(1:48, c(4,4,3), dimnames=list(
  c("P","PO","C","T"), c("LL","RR","R","Y"), c("Jerry1", "Jerry2", "Jerry3")))

column_ref <- names(which.max(Q[3,1:3, which.max(Q[3,4,])]))[1] # "R"

Some explanation:

which.max(Q[3,4,]) # return the index of the "Jerry3" slice (3)
which.max(Q[3,1:3, 3]) # returns the index of the "R" column (3)

...and then names returns the name of the index ("R").

Tags:

Indexing

R

Max