[R] matrix

gb gb at stat.umu.se
Sun Apr 23 20:55:43 CEST 2000


Is there a reason for the following behaviour?

> x <- matrix(1:6, ncol = 1)
> x
     [,1]
[1,]    1
[2,]    2
[3,]    3
[4,]    4
[5,]    5
[6,]    6
> is.matrix(x)
[1] TRUE
> is.matrix(x[1:2,])
[1] FALSE

The reason for asking is that I have a function which takes a matrix as
an argument, and in the function I "sweep" columns of subsets of the rows
of the matrix. This works fine, except when the input matrix has only one
column. Then I get

> sweep(cc[2:3, ], 2, cc.mean)
Error in aperm(array(STATS, dims[perm]), order(perm)) : 
        perm has incorrect length

If I change it to 

> sweep(matrix(cc[2:3, ]), 2, cc.mean)

it works, but it looks a little bit clumsy to me?

Göran
-----------------------------------------------------------------------
 Göran Broström, professor                        tel: +46 90 786 5223
 Department of Statistics                         fax: +46 90 786 6614
 Umeå University
 SE-90187 Umeå, Sweden                         e-mail: gb at stat.umu.se
-----------------------------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list