Re: [R] How to access a column by its label?

From: Marc Schwartz (via MN) <>
Date: Fri 04 Aug 2006 - 05:00:01 EST

On Thu, 2006-08-03 at 14:44 -0400, Neil McLeod wrote:
> Hi all,
> Is there any way to access a column of a data frame by its label (title)
> rather than its column index? For example, I'd like to be able to select
> animals[,"weight"] rather than animals[,3], if the third column of the
> "animals" data frame has the label "weight".
> Thank you!

You answered your own question...animals[,"weight"]

You can also do:





subset(animals, select = weight)

See ?Extract and ?subset for more information.

HTH, Marc Schwartz mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri Aug 04 06:12:06 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 04 Aug 2006 - 08:17:44 EST.

Mailing list information is available at Please read the posting guide before posting to the list.