[R] Warning while subsetting using Matrix package

Thaden, John J ThadenJohnJ at uams.edu
Thu Jul 6 06:53:02 CEST 2006


Hello,
  Could someone please explain the following warning while subsetting in
the Matrix package?
Thanks,
John Thaden, PhD
U. Arkansas for Med. Sci.
Little Rock AR USA

> # In the Matrix package...
> library("Matrix")
> # ...I had previously created a sparse matrix in triplet form:
> str(x)
Formal class 'dgTMatrix' [package "Matrix"] with 6 slots
  ..@ i       : int [1:923636] 1 2 3 4 5 6 7 8 9 10 ...
  ..@ j       : int [1:923636] 1 1 1 1 1 1 1 1 1 1 ...
  ..@ Dim     : int [1:2] 600 4482
  ..@ Dimnames:List of 2
  .. ..$ : chr [1:601] "50" "51" "52" "53" ...
  .. ..$ : chr [1:4482] "1" "2" "3" "4" ...
  ..@ x       : num [1:923636] 50.2 51.2 52.2 53.2 54.2 ...
  ..@ factors : list()
>
> # While subsetting x, I was surprised to get this warning: 
> y<-x[1:300,]
Warning message:
number of items to replace is not a multiple of replacement length
> # I did not get a warning, however, if I were more explicit...
> y <- x[1:300,1:4482]
>
> # Of course with a standard matrix, neither form gives a warning:
> (z <- matrix(1:12,4))
     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12
> z[1:2,]
[1,]    1    5    9
[2,]    2    6   10
> z[1:2,1:4]
[1,]    1    5    9
[2,]    2    6   10
> # I wonder what is going on?

Confidentiality Notice: This e-mail message, including any a...{{dropped}}



More information about the R-help mailing list