[R] Using 'aggregate' when dependent on row value increments

Michael A. Miller mmiller3 at iupui.edu
Thu Apr 30 21:24:32 CEST 2009


>>>>> "jim" == jim holtman <jholtman at gmail.com> writes:

    > Is this what you want:
    >> aggregate(x$Sim_1986, list(trunc(x$Latitude)), mean)
    >   Group.1 x 1 82 55.04276 2 83 60.26186 3 84 39.40297 4 85
    > 22.12000
    >> 

You could also use cut to convert Latitude to a factor:
  aggregate(x$Sim_1986, cut(x$Latitude, breaks=seq(-55,85,by=1)), mean)

Mike

    >> values between where Latitude 85, 84, 83, 82. The maximum
    >> latitude in the dataset as a whole is 83.75 and the
    >> minimum is -55.75.
    >>




More information about the R-help mailing list