zero extent arrays and apply()

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

zero extent arrays and apply()

Robin Hankin

I am having difficulty making apply() work as expected (and desired)  
with arrays
that have zero-extent dimensions.

?apply says

   If each call to 'FUN' returns a vector of length 'n', then 'apply'
      returns an array of dimension 'c(n, dim(X)[MARGIN])' if 'n > 1'.
      If 'n' equals '1', 'apply' returns a vector if 'MARGIN' has length
      1 and an array of dimension 'dim(X)[MARGIN]' otherwise. If 'n' is
      '0', the result has length 0 but not necessarily the "correct"

My reading of this is that if n=1 and MARGIN has length >1 an array
of dimension dim(X)[MARGIN] is returned.  But:

 > a <- array(0,c(3,0,4))
 > dimnames(a) <- list(a=letters[1:3],b=NULL,c=LETTERS[1:4])
 > f <- function(x){5}
 > apply(a,1:2,f)

I want  an array of dimension c(3,0,4)[1:2]  here, ie c(3,0).  In my  
the dimnames are the important thing.

Any comments anyone?

Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

[hidden email] mailing list
PLEASE do read the posting guide!