Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve dimnames #8

Open
alexpghayes opened this issue Nov 12, 2022 · 0 comments
Open

Preserve dimnames #8

alexpghayes opened this issue Nov 12, 2022 · 0 comments

Comments

@alexpghayes
Copy link
Contributor

Apparently Matrix should export:

dimScale <- function(x, d1 = 1 / sqrt(diag(x, FALSE)), d2 = d1) {
     dim.x <- dim(x)
     D1 <- Diagonal(n = dim.x[2L], x = d1)
     D2 <- if(missing(d2)) D1 else Diagonal(n = dim.x[1L], x = d2)
     y <- D1 %*% x %*% D2 # inefficient for symmetricMatrix 'x', but "general"
     if(is(x, "symmetricMatrix"))
         y <- forceSymmetric(y, x@uplo)
     y@Dimnames <- dimnames(x)
     y
}

rowScale <- function(x, d) {
     y <- Diagonal(n = nrow(x), x = d) %*% x
     y@Dimnames <- dimnames(x)
     y
}

colScale <- function(x, d) {
     y <- x %*% Diagonal(n = ncol(x), x = d)
     y@Dimnames <- dimnames(x)
     y
}

beginning with version 1.5.2, but I can't install 1.5.3 from CRAN for some reason, and the dev version I just installed with

install.packages("Matrix", repos = "http://r-forge.r-project.org/")

is apparently version 1.5.2 and doesn't appear export dimScale() or friends, so this is a problem for later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant