[R] zero extent arrays and apply()
Robin Hankin
r.hankin at noc.soton.ac.uk
Mon Feb 13 13:40:12 CET 2006
Hi
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"
dimension.
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)
numeric(0)
>
I want an array of dimension c(3,0,4)[1:2] here, ie c(3,0). In my
application,
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
More information about the R-help
mailing list