Apologies, just a typo in the first instruction (when translating the names), the question is still valid

On 21 Oct 2008, at 00:38, Ivan Alves wrote:

Dear all,

I would like to aggregate a data frame (consisting of 2 columns - one
for the bins, say factors, and one for the values) along bins and
quantiles within the bins.

I have tried

aggregate(data.frame$values, list(bin = data.frame
$bin,Quantile=cut2(data.frame$values,g=10)),sum)

but then the quantiles apply to the population as a whole and not the
individual bins. Upon this realisation I have tried

aggregate(data.frame$values, list(bin = data.frame
$bin,Quantile=tapply(data.frame$values,data.frame$bin,cut2,g=10)),sum)

which gives the following error:

Error in sort.list(unique.default(x), na.last = TRUE) :
  'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?

clearly I am doing something wrong, but cannot figure out what.  I
believe the error stems either from a. the output of tapply being a
list of a dimension equal to the number of bins, and not a list of
equal dimension as the values, or b. that somehow aggregate does not
like that the second list (of the quantiles within the bins which do not appear to be
sorted nicely)

1. Do you have a reference for doing the summation on both bins and
quantiles within the bins?
2. If not, can you give me some guidance as to what I am doing wrong
and how I can solve the sort/list issue?

Any help would be greatly appreciated

Kind regards,

Ivan Alves


        [[alternative HTML version deleted]]

______________________________________________
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.

______________________________________________
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