Suppose I have the following matrix:
cm<-structure(c(100, 200, 400, 800, 100, 200, 400, 800, 100, 200,
400, 800, 100, 200, 400, 800, 100, 200, 400, 800, 0, 0, 0, 0,
0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5,
-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4,
-0.4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1), .Dim = c(20L, 4L), .Dimnames = list(
NULL, c("Var1", "Var2", "Var3", "n1")))
and another matrix derived from it:
a4<-data.matrix(unique(cm[,1:3]))
Now, I want to find all the rows of cm
whose first three columns are equal to a4[1,]
, but doing the intutive thing:
a5<-which(cm[,1:3]==a4[1,])
fails (R 3.1.3
). For example a5[2]
is 13, but the 13th row of cm[,1:3]
ain't the same as a4[1,]
.
See Question&Answers more detail:
os