Dear all,

This seems to be working, but I'd like to make sure that I'm not doing
anything wrong.

I am using by() to construct a complicated summary statistic by
several factors in my data (specifically, the 90-50 income ratio by
city and race).

cityrace.by <- by(microdata, list(microdata$city,microdata$race),
function (x) quantile(x$income, probs=0.9) / quantile(x$income,
probs=0.5) )

I would now like to use the data created by by() as a dataset with
city-race as the unit of observation.

However, cityrace.data <- as.data.frame(cityrace.by) does not work because
"Error in as.data.frame.default(city.by) :
  cannot coerce class "by" into a data.frame"

The following is not a documented use of as.data.frame.table(), but it
seems to work.  It gives the columns slightly strange names, including
"Freq" for the statistic computed in by by() but otherwise, the
dataframe is indexed by city and race with the 90-50 ratio as the
variable

cityrace.data <- as.data.frame.table(cityrace.by)

Any objections?

Best,
Michael



-- 
Michael Ash, Associate Professor
  of Economics and Public Policy
Department of Economics and CPPA
University of Massachusetts
Amherst, MA 01003
Tel +1-413-545-6329 Fax +1-413-545-2921
Email m...@econs.umass.edu
http://people.umass.edu/maash

______________________________________________
R-help@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.

Reply via email to