[R] Using aggregate() and apply() on circular data

Waichler, Scott R Scott.Waichler at pnl.gov
Tue Jan 8 20:22:32 CET 2008


I would like to use aggregate.ts() and apply() on circular data, but I
can't figure out how to get the circular data components to pass
through:

library(circular)
x <- circular(c(20, 30, 355, 5, 345, 25), units = "degrees")

% I want to get the mean angle for each successive pair; answer should
be c(25, 0, 5):
aggregate.ts(x, ndeltat=2, FUN="mean.circular")
Error in as.circular(x) :
  (converted from warning) an object is coerced to the class 'circular'
using default value for the following components:
  type: 'angles'
  units: 'radians'
  template: 'none'
  modulo: 'asis'
  zero: 0
  rotation: 'counter'
conversion.circularxradians0counter

% Using mean() disregards the circular nature of the data:
aggregate.ts(x, ndeltat=2, FUN="mean")
Time Series:
Start = 1
End = 5
Frequency = 0.5
[1]  25 180 185

% I have similar problems with apply():
y <- matrix(x, ncol=2, byrow=T)
% Both of the following expressions yield the same error message as
above.
apply(y, 1, FUN="mean.circular")
apply(circular(y, units = "degrees"), 1, FUN="mean.circular")

I've tried passing various additional arguments to aggregate.ts() and
apply() to specify the circular components, without success.

Scott Waichler
Pacific Northwest National Laboratory
scott.waichler at pnl.gov




More information about the R-help mailing list