[R] Issue with the Matrix package

From: Tony Chiang <tchiang_at_fhcrc.org>
Date: Fri, 04 May 2007 00:07:04 +0100


Hi all,

I am wondering if this is a bug in the Matrix package or if it something that I am just getting wrong...here is an example:

> m = matrix(0,4,4)
> dimnames(m) = list(letters[1:4], letters[5:8])
> r = c("a","b","a","d")
> m[r,2] = 1
> m

  e f g h
a 0 1 0 0
b 0 1 0 0
c 0 0 0 0
d 0 1 0 0

> M = Matrix(0,4,4)
> dimnames(M) = list(letters[1:4], letters[5:8])
> M[r,2] = 1
> M

4 x 4 sparse Matrix of class "dgCMatrix"

a . 2 . .
b . 1 . .
c . . . .
d . 1 . .


The documentation reads:

" Most of the time, the function works via a traditional (_full_)

     'matrix'.  However, 'Matrix(0, nrow,ncol)' directly constructs an
     "empty" sparseMatrix, as does 'Matrix(FALSE, *)'."

So is this when an exception comes, and if so can someone explain to me why we get the 2? It would seem that it should just reassign the 1 to a 1 not add the number of times it is assigning a 1.

Cheers,
--Tony

        [[alternative HTML version deleted]]



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 03 May 2007 - 23:12:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 May 2007 - 09:31:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.