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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.