From: <markleeds_at_verizon.net>

Date: Mon, 10 Nov 2008 11:15:51 -0600 (CST)

))

))

R-help_at_r-project.org 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 Mon 10 Nov 2008 - 17:19:38 GMT

Date: Mon, 10 Nov 2008 11:15:51 -0600 (CST)

hi chris: i'm betting that there is a better/shorter more R'ish way to
do it ( if someone could provide that, it's appreciated ) but below will
get the output in the format you need. the all function tests whether
all the elements are equal so you don't need setequal although i guess
it's a matter of taste ?

as.vector((t(sapply(1:nrow(testmat1),function(.rowindex1) {

sapply(1:nrow(testmat2), function(.rowindex2) { all(testmat2[.rowindex2,] == testmat1[.rowindex1,]) }) }))

))

#===========================================================================

Hello R-users,

I have a little problem.

I compare each row of a matrix with each row of another matrix.

print(testmat1)

print(testmat2)

Both matrix differs in the last row.

Now I create a loop:

for (i in (1:4)){

for (j in (1:4)){

b <- (c(setequal(testmat1[j,],testmat2[i,])))
print(b)

}

}

R outputs me the following:

*[1] TRUE
**[1] FALSE
**[1] FALSE
**[1] FALSE
**[1] FALSE
**[1] TRUE
**[1] FALSE
**[1] FALSE
**[1] FALSE
**[1] FALSE
**[1] TRUE
**[1] FALSE
**[1] FALSE
**[1] FALSE
***[1] FALSE
**

**[1] TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE
**

sapply(1:nrow(testmat2), function(.rowindex2) { all(testmat2[.rowindex2,] == testmat1[.rowindex1,]) }) }))

))

R-help_at_r-project.org 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 Mon 10 Nov 2008 - 17:19:38 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Mon 10 Nov 2008 - 23:30:23 GMT.

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