[R] empty array

Robin Hankin r.hankin at noc.soton.ac.uk
Tue Mar 18 10:31:20 CET 2008


Hello everyone

I know other, more knowledgeable, people
have replied to Christophe's question, but
perhaps the List would be interested to know
that zero-extent arrays are useful (to me at least)
  because although such an array  has no content, the
dimname are nevertheless retained:


 > a <- array(0,dim=c(0,3))
 > dimnames(a) <- list(size=c() , fish=c("cod","skate","crab"))
 > b <- array(0,dim=c(2,0))
 > dimnames(b) <- list(size=c("huge","small"),depth=c())
 >


We can attach these arrays ---both of  which are of length 0---using  
adiag():

 > library(magic)
 > adiag(a,b)
        fish
size    cod skate crab
   huge    0     0    0
   small   0     0    0
 >


Note how the dimnames of "a" and "b" are retained in the output.
The contents of this array are the default "pad" value of adiag().

This is terribly useful in the humble workaday world
of high-dimensional magic hypercubes.




rksh



On 15 Mar 2008, at 15:33, Christophe Genolini wrote:

> Hi the list
>
> Is it possible to create an empty matrix ? I do not mean an matrix  
> with
> a single value that is NA (which is not empty) but a real empty one,
> with length=0.
>
> I do not understand why we have length(numeric()), length(factor())  
> and
> length(character()) to zero, and length(array()) to one... Any rason  
> for
> that ?
>
> Thanks
>
> Christophe
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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



More information about the R-help mailing list