Reputation: 119
I have a matrix that I suspect has some infinite elements.
I have two questions:
Thank you
Upvotes: 0
Views: 570
Reputation: 11995
Try this, but make sure your input data is of class matrix:
set.seed(1)
# make data
n <- 20
m <- 10
M <- matrix(rnorm(n*m), n, m)
# add Infs
M[sample(x = length(M), size = length(M)*0.1)] <- Inf
image(seq(n), seq(m), M, xlab = "rows", ylab = "columns")
# here is the vector that you want to multiply each row with
multVec <- seq(m)
# apply with removal of non-finite values
res <- apply(M, 1, function(x){
tmp <- x * multVec
sum(tmp[is.finite(tmp)])
})
Upvotes: 1