В Sun, 24 Apr 2022 17:05:55 +0200
Uwe Freier <u...@freier.de> пишет:

> ifelse(x[i] == 0, A[,i], 0)

Hint: what does ifelse return instead of a vector of length nrow(A)?

Since you're checking conditions of length 1, you can safely use `if
(x[i] == 0) A[,i] else 0` here, or you can transform the `x` vector
into a boolean matrix of the correct shape to guide the substitution:

X <- matrix(as.logical(x), nrow(A), ncol(A), byrow = TRUE)
ifelse(X, 0, A)

-- 
Best regards,
Ivan

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to