Skip to content
Prev 58996 / 63424 Next

more Matrix weirdness

I'm not sure what you mean by "not for the base R vector classes".
Historically, the simpler class (or mode) gets coerced to the more
complex class (or mode).

    x <- y <- 1:10
    y [1] <- 1

    (class (x) == class (y) ) #FALSE

Also, I note the behavior of multiplication of a matrix with a Matrix.

    library (Matrix)

    m <- matrix (1:16, 4, 4)
    M <- Matrix (1:16, 4, 4)

    as.vector (class (m * M) )   #dgeMatrix
    as.vector (class (M * m) )   #dgeMatrix
    as.vector (class (m %*% M) ) #dgeMatrix
    as.vector (class (M %*% m) ) #dgeMatrix

So, here also, the output is a Matrix, regardless of the type of
multiplication, or the order of the operands.

But the following surprised me:

    k <- m
    mode (k) <- "complex"
    k %*% M
Message-ID: <CAB8pepxxLEWVOo8LOueUQuaMF30aP=HOeVc+YvkEDVYZ5Vnb8g@mail.gmail.com>
In-Reply-To: <AM0PR0102MB344323F157EA05E0A78846CFAE240@AM0PR0102MB3443.eurprd01.prod.exchangelabs.com>