[R] How to retrieve a vector of a data.frame's variable attributes?

From: Bacou, Melanie <mel_at_mbacou.com>
Date: Sun, 17 Apr 2011 16:21:13 -0400


I have a data.frame with 100 variables and I have assigned a "label", "units" and "category" attribute to each variable. I would like to reorder the variables in the data.frame by the "category" attributes but can't find a way.

For example, the first variable is:

> attributes(hh$aez)

[1] "coastal" "forest" "savannah"


[1] "labelled" "factor"


[1] ecological zone
93 Levels: 10 quantiles of welfare ... year of the interview


[1] class
24 Levels: '05 PPP USD / year cedis / year cedis /year class geo-1 ... years


[1] geography
7 Levels: agriculture demography design expenditure geography ... welfare

I have tried:

hh <- hh[, order(attr(hh, "category"))]
hh <- hh[, order(attr(hh[, 1:100], "category"))]
hh <- hh[, order(attr(dimnames(hh), "category"))]

but all the right-hand side assignments above return NULL.

Thanks very much for your help with this simple task!


 Melanie Bacou
 3110 Wisconsin Ave, NW
 Washington DC, 20016
 +1 (202) 492-7978

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 17 Apr 2011 - 21:07:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 17 Apr 2011 - 22:40:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive