[R] using tapply with multiple variables

jim holtman jholtman at gmail.com
Sat Apr 30 22:10:46 CEST 2011


Since you did provide a description of your data (e.g., at least
'str(ALLDATA)') so that we know its structure, I will take a guess:

tapply(ALLDATA$Correct, list(ALLDATA$Subject, ALLDATA$Time),
function(x)sum(x=="C"))

On Sat, Apr 30, 2011 at 3:28 PM, Kevin Burnham <kburnham at gmail.com> wrote:
> HI All,
>
> I have a long data file generated from a minimal pair test that I gave to
> learners of Arabic before and after a phonetic training regime.  For each of
> thirty some subjects there are 800 rows of data, from each of 400 items at
> pre and posttest.  For each item the subject got correct, there is a 'C' in
> the column 'Correct'.  The line:
>
> tapply(ALLDATA$Correct, ALLDATA$Subject, function(x)sum(x=="C"))
>
> gives me the sum of correct answers for each subject.
>
> However, I would like to have that sum separated by Time (pre or post).  Is
> there a simple way to do that?
>
>
> What if I further wish to separate by Group (T or C)?
>
> Thanks,
> Kevin
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list