Re: [R] counting the occurrences of vectors

2004-07-06 Thread Marc Schwartz
On Mon, 2004-07-05 at 23:22, Gabor Grothendieck wrote: Marc Schwartz MSchwartz at MedAnalytics.com writes: the likely overhead involved in paste()ing together the rows to create objects I thought I would check this and it seems that in my original f1 function its not really the

Re: [R] counting the occurrences of vectors

2004-07-05 Thread Marc Schwartz
On Sun, 2004-07-04 at 19:28, Spencer Graves wrote: I see a case where f1 gives the wrong answer: b - array(c(a:b, a, c, b:c), dim=c(2,2)) a - b[c(1,1),] For these two matrices, f1(a,b) == c(2,2), while f2(a,b) == c(2,0). If b does not contain :, e.g., if it is

Re: [R] counting the occurrences of vectors

2004-07-05 Thread Gabor Grothendieck
Marc Schwartz MSchwartz at MedAnalytics.com writes: row.match.count - function(m1, m2) { if (ncol(m1) != (ncol(m2))) stop(Matrices must have the same number of columns) if (typeof(m1) != (typeof(m2))) stop(Matrices must have the same data type) m1.l -

Re: [R] counting the occurrences of vectors

2004-07-05 Thread Gabor Grothendieck
Marc Schwartz MSchwartz at MedAnalytics.com writes: the likely overhead involved in paste()ing together the rows to create objects I thought I would check this and it seems that in my original f1 function its not really the paste itself that's the bottleneck but applying the paste. If we

RE: [R] counting the occurrences of vectors

2004-07-04 Thread Ravi Varadhan
Thanks to Gabor, Marc, and Spencer for their elegant solutions. Gabor's first solution worked the best for me. Best, Ravi. From: [EMAIL PROTECTED] on behalf of Gabor Grothendieck Sent: Sat 7/3/2004 12:12 PM To: [EMAIL PROTECTED] Subject: Re: [R] counting

Re: [R] counting the occurrences of vectors

2004-07-04 Thread Spencer Graves
the best for me. Best, Ravi. From: [EMAIL PROTECTED] on behalf of Gabor Grothendieck Sent: Sat 7/3/2004 12:12 PM To: [EMAIL PROTECTED] Subject: Re: [R] counting the occurrences of vectors Ravi Varadhan rvaradha at jhsph.edu writes: Hi: I have two matrices

[R] counting the occurrences of vectors

2004-07-03 Thread Ravi Varadhan
Hi: I have two matrices, A and B, where A is n x k, and B is m x k, where n m k. Is there a computationally fast way to count the number of times each row (a k-vector) of B occurs in A? Thanks for any suggestions. Best, Ravi. [[alternative HTML version deleted]]

Re: [R] counting the occurrences of vectors

2004-07-03 Thread Spencer Graves
What have you tried? Have you considered something like the following: n - 4 m - 3 k - 2 A - array(1, dim=c(n, k)) B - array(1, dim=c(m,k)) BinA - rep(NA, m) tA - t(A) for(i in 1:m){ BinA[i] - sum(apply(B[i,]==tA, 2, sum)==k) } BinA [1] 4 4 4 hope this helps. spencer graves Ravi

Re: [R] counting the occurrences of vectors

2004-07-03 Thread Marc Schwartz
On Sat, 2004-07-03 at 09:31, Ravi Varadhan wrote: Hi: I have two matrices, A and B, where A is n x k, and B is m x k, where n m k. Is there a computationally fast way to count the number of times each row (a k-vector) of B occurs in A? Thanks for any suggestions. Best, Ravi. How

Re: [R] counting the occurrences of vectors

2004-07-03 Thread Gabor Grothendieck
Ravi Varadhan rvaradha at jhsph.edu writes: Hi: I have two matrices, A and B, where A is n x k, and B is m x k, where n m k. Is there a computationally fast way to count the number of times each row (a k-vector) of B occurs in A? Thanks for any suggestions. Best, Ravi. Here are