[R] How create vector that sums correct responses for multiple subjects?

Hadley Wickham hadley at rice.edu
Thu Mar 24 21:46:39 CET 2011


On Thu, Mar 24, 2011 at 2:24 PM, Kevin Burnham <kburnham at gmail.com> wrote:
> I have a data file with indicates pretest scores for a linguistics
> experiment.  The data are in long form so for each of 33 subjects there are
> 400 rows, one for each item on the test, and there is a column called
> ‘Correct’ that shows ‘C’ for a correct response and ‘E’ for an incorrect
> response.  I am trying to write a formula that will create a vector that
> indicates the number of correct answers for each subject.
>
> nrow(pretestdata[(pretestdata$Subject=="1" & pretestdata$Correct=="C"),])
>
>
>
> gives the number of correct responses for subject 1, but I would like a
> vector that indicates the number correct for each of 33 subjects.

How about

with(pretestdata, table(Subject, Correct))

?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list