[R] Conditional Evaluation
Thiem Alrik
thiem at sipo.gess.ethz.ch
Tue Sep 27 01:03:52 CEST 2011
Dear mailing list,
how can I identify all those rows of matrix B which fulfill some condition based on another matrix A? More precisely,
A <- matrix(c(1, 1, 0, 1, -9, 1, -9, 1, 0, 0, 1, 1, 0, -9, 1, 0, -9, 0, 1, 1, 1, -9, 1, 1, 1), ncol = 5, byrow = TRUE)
B <- matrix(c(0,0,1,0,0,0,1,1,0,0,0,0,1,1,0,1,0,1,1,0,0,1,1,1,0,1,1,1,1,0,0,0,1,0,1,1,
0,1,0,1,0,1,1,0,1,1,1,1,0,1,0,0,1,1,1,0,1,1,1,1,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1), ncol = 5, byrow = TRUE)
Row 1 in A has value 1 on element 1, 2 and 4. Which rows in B also display this pattern? Only row 6.
Row 2 in A has value 1 on element 1 and 3. Which rows in B also display this pattern? Rows 4, 6, 8 and 10.
...
Row 5 in A ...
C <- rbind(4, 6, 8, 10, ...)
How can I collect together all those rows from B to create a new matrix C?
Thanks a lot,
Alrik
More information about the R-help
mailing list