Skip to content

tapply problem

4 messages · robin hankin, PIKAL Petr, Mark Myatt

#
Hello everybody.

I have a question that has stumped me and the usual "apply" tricks
don't seem to work.  I run a course where each student's performance
is marked by one or more assessors. 

I have a data frame containing students' names, assessors' names and
their marks, arranged as follows:


        ID       student   assessor  Q1A  Q1B  Q1C  Q2A  Q2B  Q3
1  2152833    Fred.Smith      Robin 15.0 17.0 13.0 14.0 13.0  8.0
2  2152833    Fred.Smith      Steph 14.0 13.0 11.0 16.0 13.0  8.0
3  2152833    Fred.Smith      Julie 15.0 17.0 13.0 17.0 13.0  8.0
4  9821091    Joe.Bloggs       John 13.0 12.0 12.0 15.0 12.0  8.0
5  9821091    Joe.Bloggs      Julie   NA   NA   NA 18.0 14.0  8.0
6  9821091    Joe.Bloggs      Robin 12.0 12.5   NA 16.0 13.5  8.0
7  9821091    Joe.Bloggs      Steph   NA   NA 12.0 17.0 12.5  NA
8  9791734     Bob.Jones      Julie 13.0 12.0  8.0 16.0 13.0  8.0
9  9791734     Bob.Jones      Robin 11.0 12.0  7.0 14.0 11.0  8.0
...


note that some students are marked by more assessors than others.


What I want is each student's mean mark for each question, averaged
over the appropriate assessors.  Is there a neat vectorized method I
could use?

The best I can come up with is "tapply(x$Q1A,x$name,mean,na.rm=T)" but
this works question-by-question and I would like a reduced data frame
with the same column headings.


this is driving me crazy; thanks in advance!



-- 

Robin Hankin, Lecturer,
School of Environmental and Marine Science
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042



--f9295XO03655.1002013533/r.hankin.sems.auckland.ac.nz--
#
On 18 Oct 2001 at 16:21, Robin Hankin wrote:

            
tricks
performance
and
Q3
8.0 2
7
8
others.
averaged
method I
If I understood it correctly you need something like that:

        ID student assessor Q1A  Q1B Q1C Q2A  Q2B Q3
1  2152833    Fred    Robin  15 17.0  13  14 13.0  8
2  2152833    Fred    Steph  14 13.0  11  16 13.0  8
3  2152833    Fred    Julie  15 17.0  13  17 13.0  8
4  9821091     Joe     John  13 12.0  12  15 12.0  8
5  9821091     Joe    Julie  NA   NA  NA  18 14.0  8
6  9821091     Joe    Robin  12 12.5  NA  16 13.5  8
7  9821091     Joe    Steph  NA   NA  12  17 12.5 NA
8  9791734     Bob    Julie  13 12.0   8  16 13.0  8
9  9791734     Bob    Robin  11 12.0   7  14 11.0  8
***10 9821091     Joe     John  14 15.0  14  15 11.0  9***

I added one line because each student was marked by the assessor 
only once in your example...
Group.1 Group.2  Q1A  Q1B Q1C Q2A  Q2B  Q3
***1     Joe    John 13.5 13.5  13  15 11.5 8.5***
2     Bob   Julie 13.0 12.0   8  16 13.0 8.0
3    Fred   Julie 15.0 17.0  13  17 13.0 8.0
4     Joe   Julie   NA   NA  NA  18 14.0 8.0
5     Bob   Robin 11.0 12.0   7  14 11.0 8.0
6    Fred   Robin 15.0 17.0  13  14 13.0 8.0
7     Joe   Robin 12.0 12.5  NA  16 13.5 8.0
8    Fred   Steph 14.0 13.0  11  16 13.0 8.0
9     Joe   Steph   NA   NA  12  17 12.5  NA
"tapply(x$Q1A,x$name,mean,na.rm=T)" but
frame
"help",
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
.
Petr Pikal
petr.pikal at precheza.cz
p.pik at volny.cz


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
5 days later
#
Hi Petr

many thanks for your help here.
[deleted].


It worked perfectly (my problem was that I didn't know about the
"aggregate" function). 



kia ora (Maori for "cheers!")


robin
#
Robin Hankin <r.hankin at auckland.ac.nz> writes:
Sounds like Italian for "What is the time?" Is the Maori the source for
the name of the soft drink? It makes more sense that the Italian.

Mark


--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._