Re: [R] How to compare rows of two matrices

From: Stephen C. Upton <supton_at_referentia.com>
Date: Thu 24 Aug 2006 - 20:26:31 EST

Does this work for you?
dd <- mapply("==",train,test)
 > dim(dd) <- dim(train)
 > dd

      [,1] [,2] [,3] [,4]

[1,] FALSE FALSE FALSE FALSE
[2,]  TRUE FALSE FALSE  TRUE
[3,] FALSE FALSE FALSE FALSE
[4,] FALSE FALSE FALSE FALSE
[5,] FALSE FALSE FALSE  TRUE

HTH
steve

Muhammad Subianto wrote:
> 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
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Aug 24 20:46:03 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 24 Aug 2006 - 22:26:20 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.