[R] Stymied by plyr

From: Stuart Luppescu <slu_at_ccsr.uchicago.edu>
Date: Wed, 20 Apr 2011 22:14:53 -0500


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 
才文と智奈美の父 -=- Kernel 2.6.36-gentoo-r5 
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)

______________________________________________
R-help_at_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.
Received on Thu 21 Apr 2011 - 03:20:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Apr 2011 - 08:40:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive