[R] row equality.

2005-02-13 Thread James Bullard
I think that this is an easy one... I have a matrix where each row is an (x,y,z) triplet. Given a potential (xnew,ynew,znew) triplet I want to know if the matrix already contains a row with the new values (the space already has that point). I can do it using a for loop, but I would like to know

RE: [R] row equality.

2005-02-13 Thread Liaw, Andy
Try something like: x1 - matrix(sample(1:5, 30, replace=TRUE), ncol=3) x2 - x1[4,] which(colSums(abs(t(x1) - x2)) == 0) [1] 4 Note: If the data are not all integers, you probably should test whether the absolute sum differences is less than some very small number, rather than == 0. This