matrices and arrays loose dimension after multiplying with scalar (PR#1979)

oehl_list@gmx.de oehl_list@gmx.de
Tue, 3 Sep 2002 17:45:33 +0200 (MET DST)


A matrix or array with one of its dimensions having zero elements looses its
dimension after multiplying with scalar.
Admittedly this is an extreme case, however it DOES make sense to retain an
objects formal structure after multiplying with a scalar, as e.g. a matrix
with zero rows IS a legal object in S. BTW, the prototype does retain the
dimension.

Best


Jens Oehlschlägel


# replication code at the end


# R1.5.1
> m <- matrix(1, nrow=0, ncol=3)
> m
     [,1] [,2] [,3]
> m*100
numeric(0)
> 
> m <- matrix(1, nrow=3, ncol=0)
> m
> m*100
numeric(0)
> 
> a <- array(1, dim=c(2, 2, 0))
> a
> a*100
numeric(0)


# Prototype
> m <- matrix(1, nrow=0, ncol=3)
> m
integer matrix: 0 rows, 3 columns.
> m*100
integer matrix: 0 rows, 3 columns.
>
> m <- matrix(1, nrow=3, ncol=0)
> m
integer matrix: 3 rows, 0 columns.
> m*100
integer matrix: 3 rows, 0 columns.
>
> a <- array(1, dim=c(2, 2, 0))
> a
integer array: 2 by 2 by 0
> a*100
integer array: 2 by 2 by 0



# replication code

m <- matrix(1, nrow=0, ncol=3)
m
m*100

m <- matrix(1, nrow=3, ncol=0)
m
m*100

a <- array(1, dim=c(2, 2, 0))
a
a*100


> version
         _              
platform i386-pc-mingw32
arch     i386           
os       Win32          
system   i386, mingw32  
status                  
major    1              
minor    5.1            
year     2002           
month    06             
day      17             
language R    

-- 




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._