[R] aggregate syntax for grouped column means

2011-11-29 Thread Juliet Hannah
I am calculating the mean of each column grouped by the variable 'id'. I do this using aggregate, data.table, and plyr. My aggregate results do not match the other two, and I am trying to figure out what is incorrect with my syntax. Any suggestions? Thanks. Here is the data. myData -

Re: [R] aggregate syntax for grouped column means

2011-11-29 Thread Jeff Newmiller
The semantics for na.rm are different for aggregate than for the other options. The former removes any rows that contain an NA prior to performing the computation, the latter methods work column-wise. You have to decide which is correct for your purposes.

Re: [R] aggregate syntax for grouped column means

2011-11-29 Thread Justin Haynes
look at just your data that is in that first id category and I bet you can figure it out! myData[myData$id=='0m11',] var1 var2 id 10 30.79 32.15 0m11 11 30.79 32.39 0m11 12 30.94NA 0m11 aggregate performs the na.rm step on the entire row thus, a mean of 30.79. data.table and plyr