Getting Column Names in R
May 31, 2011
I learned something new today:
mymax = apply(mydata, 1, which.max) maxname = names(mydata)[mymax]
I’ve written a function to do this in the past, inserted where which.max sits, but the second line has never really occurred to me as being possible. Yet another expansion of my thinking in R.
Advertisement