[R] How to retrieve a vector of a data.frame's variable attributes?
Bacou, Melanie
mel at mbacou.com
Sun Apr 17 22:21:13 CEST 2011
Hi,
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)
$levels
[1] "coastal" "forest" "savannah"
$class
[1] "labelled" "factor"
$label
[1] ecological zone
93 Levels: 10 quantiles of welfare ... year of the interview
$units
[1] class
24 Levels: '05 PPP USD / year cedis / year cedis /year class geo-1 ... years
$category
[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!
--Mel.
_______________________
Melanie Bacou
3110 Wisconsin Ave, NW
Washington DC, 20016
+1 (202) 492-7978
mel at mbacou.com
More information about the R-help
mailing list