[datatable-help] Data table syntax

Dennis Murphy djmuser at gmail.com
Tue Sep 7 12:18:15 CEST 2010


Hi:

It seems to me that another way to handle this problem easily would be to
add a variable indicating the 2009 school before converting it to a data
table. The function is simple enough: find the max SCHOOL_NUMBER per
STUDENT_ID and use ave() to map it to all rows with the same STUDENT_ID.

library(data.table)

txt$SCHOOL2009 <- with(txt, ave(SCHOOL_NUMBER, STUDENT_ID, FUN = max))
dtxt <- data.table(txt)
dtxt[YEAR == 2008, mean(SCORE), by = 'SCHOOL2009']
     SCHOOL2009   V1
[1,]        200 48.2
[2,]        400 53.0

As this is my first posting on this list, how do I follow-up to an existing
thread?

Dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20100907/cc840efb/attachment.htm>


More information about the datatable-help mailing list