[S] Why isn't BYROW=T working here?

B. Rey de Castro (decastro@hsph.harvard.edu)
Sun, 18 Oct 1998 11:29:38 -0400 (EDT)


I am running S-Plus 3.3 in Windows95 (Pentium 200 MHz, 32 MB RAM),
and I cannot understand why this simple call to matrix() with the byrow=T
option has no effect (see the interactive S-Plus output below). I have
also included the original S-Plus code for the matrix() function, but
there doesn't seem to be anything illuminating there.

Thanks to anybody who can shed light on this. I know that a
transpose of the matrix prior to reshaping with matrix() will equate to
the simpler call: matrix(...,byrow=T), but I am concerned that I am either
missing an important S-Plus programming concept or my S-Plus configuration
is faulty (unlikely since my S-Plus installation is recent).

> x
[,1] [,2]
[1,] 1 2
[2,] 3 4
> matrix(x,1,4)
[,1] [,2] [,3] [,4]
[1,] 1 3 2 4
> matrix(x,1,4,byrow=T)
[,1] [,2] [,3] [,4]
[1,] 1 3 2 4

> matrix
function(data = NA, nrow = 1, ncol = 1, byrow = F, dimnames = NULL)
{
if(missing(nrow))
nrow <- ceiling(length(data)/ncol)
else if(missing(ncol))
ncol <- ceiling(length(data)/nrow)
dim <- c(nrow, ncol)
if(length(dim) != 2)
stop("nrow and ncol should each be of length 1")
if(byrow)
t(array(data, dim[2:1], rev(dimnames)))
else array(data, dim, dimnames)
}

Thanks,
REY DE CASTRO

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news