Skip to content
Prev 110869 / 398498 Next

delete selecting rows and columns

A one-dimensional delete might be faster:

n <- 4000
m <- 0.01
matr <- matrix(1:(n^2), n, n)
excl_r <- sample(n, m*n)
incl_r <- setdiff(1:n, excl_r)
excl_c <- sample(n, m*n)
incl_c <- setdiff(1:n, excl_c)
system.time(matr[-excl_r, -excl_c])
system.time(
{ m4 <- matr[outer(incl_r, incl_c, function(i, j) i + n*(j - 1)) ]
  dim(m4) <- c(length(incl_r), length(incl_c))
}          )


Heikki Kaskelma
jastar wrote: