# [R] Stymied by plyr

Stuart Luppescu slu at ccsr.uchicago.edu
Thu Apr 21 05:14:53 CEST 2011

```Hello, This is my first time trying to use plyr, and I'm getting
nowhere. I have teacher ratings data (1:4), on 10 components, by
external observers and internal observers, in schools in areas. I want
to calculate the percentage of each rating given on each component, by
each type of observer, within each school, within each area. The data
look like this:

unit area ext.obs rating comp
11 77777    11       0      3    1
12 77777    11       0      4    2
13 77777    11       0      3    3
14 77777    11       0      4    4
15 77777    11       0      3    5
16 77777    11       0      3    6
17 77777    11       0      3    7
18 77777    11       0      3    8
19 77777    11       0      3    9
20 77777    11       0      3   10

I thought this would be a perfect application for plyr. I tried this:

calc.pct <- function(x) {
table(x)/sum(table(x))
}

pcts <- ddply(test.school, .(area, ext.obs, comp), calc.pct, x=rating)
Error in .fun(piece, ...) : unused argument(s) (piece)

Then I tried this:
pcts <- ddply(test.school, .(area, ext.obs, comp), .(calc.pct(rating)))
Error in .fun(piece, ...) : attempt to apply non-function

I tried all kinds of other variations but with no success. Can someone
give me some pointers?

Thanks.
--
Stuart Luppescu -=- slu .at. ccsr.uchicago.edu
University of Chicago -=- CCSR

Lars Strand: Will R run under Windows Pocket PC? Brian D. Ripley: We
don't know! There are no binary versions of R for that platform, but
perhaps you could find a suitable compiler and manage to build the
sources. Outside pure mathematics it is usually very hard to establish
that something cannot be done (and it can be very hard in pure
mathematics, too). -- Lars Strand and Brian D. Ripley R-help (November
2004)

```