[R] Gini index of frequencies in a data frame

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Wed Feb 13 01:40:15 CET 2008


several remarks which might help you to improve your code (and your style
of asking questions):

> I wish to calculate the Gini index (ineq from same package) and some
> other indices for the diameter distribution of each plot (df dgtot).
> dgtot:
>     IDPlot    Diameter(cm)

I would recommend to use names that would also work as variable names,
especially if you're a beginner, i.e., better use "Diameter" omitting the

> I use:
> > aggregate(dgtot,by=list(dgtot$IDSupr),FUN=ineq(dsp))

The argument FUN must be a function (as the name tries to convey). Above,
you evaluate the function which leads to the error because you can't do
because dsp is a function which makes no sense as the first argument of

> dsp <- function(x) # compute frequency distribution for each plot
> {
>  cd<-seq(5,max(x),by=2)
>  Fi <<- table(cut(x, br = seq(5, max(x)+1, 2), right = FALSE))
>  K <- length(names(Fi))
> }

This is really not good programming style with "<<-" and without
explicitely returning something useful. Probably, you want to return Fi,
but I'm not sure...

> I'm at the beginning in R and I kindly request your experienced help.

Have a look at the R introduction or some some book which gets you
started. If you want to ask anything on R-help...

> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

This also tells you to choose a meaningful subject. Your problem was not
at all about the "ineq" package which shouldn't have been too difficult to
find out.


More information about the R-help mailing list