[R] empty array
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Mar 15 17:02:12 CET 2008
On Sat, 15 Mar 2008, Gabor Csardi wrote:
> On Sat, Mar 15, 2008 at 04:33:32PM +0100, 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.
>
> Sure:
>
>> matrix(nrow=0, ncol=5)
> [,1] [,2] [,3] [,4] [,5]
>> a <- array( dim=c(5,4,0) )
>> dim(a)
> [1] 5 4 0
>> length(a)
> [1] 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 ?
>
> That i don't know, maybe someone else does.
See the reference on the help page for array and section 3.3.3 of the R
FAQ (about the 16th item). When R was first developed, S did not allow
zero dimensions and so the minimum length for an array (or matrix) was
one.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list