[R] ddply with mean and max...

Justin jtor14 at gmail.com
Wed May 11 18:46:44 CEST 2011


I'm trying to use ddply to compute summary statistics for many variables
splitting on the variable site.  however, it seems to work fine for mean() but
if i use max() or min() things fall apart.  whats going on?

 test.set<-data.frame(site=1:10,x=.Random.seed[1:100],y=rnorm(100))
 means<-ddply(test.set,.(site),mean)
 means
   site          x           y
1     1  -97459496 -0.14826303
2     2 -150246922 -0.29279556
3     3  471813178  0.13090210
4     4 -655451621  0.07908207
5     5 -229505843  0.10239588
6     6 -667025397 -0.34930275
7     7  510041943  0.20547460
8     8  270993292 -0.63658199
9     9  264989314  0.09695455
10   10 -199965142 -0.07202699
 maxes<-ddply(test.set,.(site),max)
 maxes
   site         V1
1     1 1942437227
2     2 2066224792
3     3 2146619846
4     4 1381954134
5     5 1802867123
6     6 1786627153
7     7 1951106534
8     8 1498358582
9     9 2022046126
10   10 1670904926

Can you all shed some light on this? I'm stumped!

Thanks,
Justin



More information about the R-help mailing list