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
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

Reply via email to