[R] fusion of two matrices (numerical and logical)
Vivek Sutradhara
v|vek@utr@ @end|ng |rom gm@||@com
Sat Sep 5 20:18:07 CEST 2020
Hi
I would like to get help in combining two matrices. Here is my example:
A <- 1:20
B <- matrix(A,nrow=5,ncol=4)
# B is a numerical matrix
C <- B<7
C[4,4] <- TRUE
# C is a logical matrix
# if I combine A and C, I get a vector
D1 <- A[C==TRUE]
D1
D2 <- A[C==FALSE]
D2
I want to get a matrix with the same dimensions as matrix A. At the
coordinates given by the vector D1, I want to retain the values in
matrix A. At the locations in D2, I want a zero value.
I want to know if I can do this without using any loops.
Thanks, Vivek
[[alternative HTML version deleted]]
More information about the R-help
mailing list