An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20060803/4d6b7dde/attachment.pl
How to access a column by its label?
3 messages · Neil McLeod, vincent at 7d4.com, Marc Schwartz (via MN)
?colnames hih
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: animals$weight or animals[["weight"]] or subset(animals, select = weight) See ?Extract and ?subset for more information. HTH, Marc Schwartz