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]]

______________________________________________
[email protected] 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.

Reply via email to