Skip to content
Back to formatted view

Raw Message

Message-ID: <2248a612-6c0c-aaf6-1699-a93029b31c2d@auckland.ac.nz>
Date: 2018-11-07T20:33:37Z
From: Rolf Turner
Subject: Problem with the matrix() function.

In the course of writing a bit of somewhat convoluted code I recently 
made a silly error that revealed the following phenomenon:

m <- matrix(1:10,nrow=2,ncol=c(5,4))

produces

>      [,1] [,2] [,3] [,4] [,5]
> [1,]    1    3    5    7    9
> [2,]    2    4    6    8   10

That is, the nonsense value of c(5,4) for the "ncol" argument is 
accepted, without comment --- the first entry of the given ncol argument 
is used.

It might be argued that this is a reasonable accommodation of the user's 
ineptitude.  I am of the opinion that an error should be thrown if the
value of ncol is not an integer scalar.

I have also discerned that if ncol is not an integer, it is replaced by 
its floor value.

Is this a Good Thing?

What do others think?

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276