Skip to content

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

1 message · Jens Oehlschlägel

#
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
[,1] [,2] [,3]
numeric(0)
numeric(0)
numeric(0)


# Prototype
integer matrix: 0 rows, 3 columns.
integer matrix: 0 rows, 3 columns.
integer matrix: 3 rows, 0 columns.
integer matrix: 3 rows, 0 columns.
integer array: 2 by 2 by 0
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
_              
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