[R] How to compare rows of two matrices
    Muhammad Subianto 
    msubianto at gmail.com
       
    Thu Aug 24 12:03:31 CEST 2006
    
    
  
Dear all,
I have a dataset
train <- cbind(c(0,2,2,1,0), c(8,9,4,0,2), 6:10, c(-1, 1, 1, -1, 1))
test <- cbind(1:5, c(0,1,5,1,3), c(1,1,2,0,3) ,c(1, 1, -1, 1, 1))
I want to find which rows of train and test it different in its last
column (column 4).
The solution must be something like
train
     [,1] [,2] [,3] [,4]
[1,]    0    8    6   -1
[3,]    2    4    8    1
[4,]    1    0    9   -1
test
     [,1] [,2] [,3] [,4]
[1,]    1    0    1    1
[3,]    3    5    2   -1
[4,]    4    1    0    1
I have tried with
matrix(train %in% test, dim(train))
apply(train, 1, paste, collapse="") %in% apply(test, 1, paste, collapse="")
It doesn't work.
How can I do.
Thanks for any help.
Best, Muhammad Subianto
    
    
More information about the R-help
mailing list