Skip to content

Instantly share code, notes, and snippets.

@markmfredrickson
Created August 5, 2013 16:52
Show Gist options
  • Save markmfredrickson/6157476 to your computer and use it in GitHub Desktop.
Save markmfredrickson/6157476 to your computer and use it in GitHub Desktop.
How to look at submatrices of InfinitySparseMatrix objects
library(optmatch)
example(match_on)
#' @param x An ISM or blocked ISM
#' @param rs Names of rows to keep
#' @param cs Names of columns to keep
submatrix <- function(x, rs, cs) {
subset(x,
x@rownames %in% rs,
x@colnames %in% cs)
}
myr <- c("B", "F")
myc <- c("I", "d")
# non-blocked matrix:
as.matrix(submatrix(match_on.examples$pscal, myr, myc))
# blocked matrix:
as.matrix(submatrix(match_on.examples$ps3, myr, myc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment