[datatable-help] Data table syntax

Matthew Dowle mdowle at mdowle.plus.com
Tue Sep 7 13:27:08 CEST 2010


Hi Dennis,

Welcome to the list.

To reply to a particular part of a thread you can use any of the mirrors
listed on the data.table homepage. I like Nabble (it's search is good
too). You can also post via your newsreader or from Google groups.
As long as you are subscribed to the Mailman list, as you must be
already, then you can find a part of a thread on that mirror and reply
to it from there. Just like r-help. You can bcc from Nabble too (but
not cc afaik).

ave() uses the lapply(split(...)) paradigm, though. That's inefficient.
== is a 'vector scan' so we try to avoid that in the i wherever possible.

Matthew

"Dennis Murphy" <djmuser at gmail.com> wrote in message 
news:AANLkTinQkr-6oe_bWv3ZF76RK11ZTmTrNfq9SzqCh5+F at mail.gmail.com...
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
datatable-help at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help 





More information about the datatable-help mailing list