Re: [R] matrix indexing

2006-03-15 Thread Gabor Grothendieck
Try this: matA[c(matB)] In fact even this works for your example although in general it couldbe problematic since a two column matrix index has special meaning: matA[matB] On 3/15/06, tom wright [EMAIL PROTECTED] wrote: Can someone please give me a pointer here. I have two matrices matA

Re: [R] matrix indexing

2006-03-15 Thread Marc Schwartz (via MN)
On Wed, 2006-03-15 at 06:03 -0500, tom wright wrote: Can someone please give me a pointer here. I have two matrices matA A B C 1 5 2 4 2 2 4 3 3 1 2 4 matB A B C 1 TRUEFALSE TRUE 2

Re: [R] matrix indexing

2006-03-15 Thread Andy Bunn
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of tom wright Sent: Wednesday, March 15, 2006 6:04 AM To: R-Stat Help Subject: [R] matrix indexing Can someone please give me a pointer here. I have two matrices matA A B C 1

Re: [R] matrix indexing

2006-03-15 Thread Dimitris Rizopoulos
matA[matB] or matA[!matB] Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/

Re: [R] matrix indexing

2006-03-15 Thread Philippe Grosjean
This is really elementary indexing in S language: matA[matB] Best, Philippe Grosjean tom wright wrote: Can someone please give me a pointer here. I have two matrices matA A B C 1 5 2 4 2 2 4 3 3 1 2 4 matB A

Re: [R] matrix indexing

2006-03-15 Thread vito muggeo
Dear tom, is the following what you are looking for? a=matrix(runif(9),3,3) a [,1] [,2] [,3] [1,] 0.9484247 0.9765431 0.6169739 [2,] 0.8423545 0.3137295 0.4031847 [3,] 0.6724235 0.1076373 0.2356923 b-matrix(sample(c(TRUE,FALSE),size=9,replace=TRUE),3,3) b [,1]

Re: [R] matrix indexing

2006-03-15 Thread tom wright
Thanks everyone. Obvious when you think about it, and you check that both the matrices your trying it with are actually matrices... instead of one being a list. On Wed, 2006-15-03 at 06:03 -0500, tom wright wrote: Can someone please give me a pointer here. I have two matrices matA A

Re: [R] Matrix indexing in a loop

2006-02-17 Thread Pontarelli, Brett
Do you have to use a loop? The following function should do what you want for the 1st order: rook = function(Y) { rsub = function(Z) { X = matrix(0,nrow(Z),ncol(Z)); X[1:(N-1),1:M] = X[1:(N-1),1:M] + Z[2:N,1:M]; X[2:N,1:M] = X[2:N,1:M] +

Re: [R] matrix indexing

2005-08-18 Thread Ben Rich
Hi, you might not consider this more elegant, but how about this x[-apply(ind, 1, function(i) (i[1]-1)*nrow(x) + i[2])] Ben On 8/18/05, toka tokas [EMAIL PROTECTED] wrote: Dear R-users, I was wondering for the following: Let 'x' be a matrix and 'ind' and indicator matrix, i.e., x -

Re: [R] matrix indexing

2005-08-18 Thread Martin Lam
x - array(1:20, dim = c(4, 5)) ind - array(c(1:3, 3:1), dim = c(3, 2)) # instead of using ind (pairs of coordinates) for getting the items in the matrix, you can convert it to a list of single coordinates to point to the item in the matrix: # t = transpose # nrow = get the number of rows indices

Re: [R] Matrix Indexing

2004-11-07 Thread Gabor Grothendieck
Kim Fai Wong gokim19 at hotmail.com writes: : : Hi, : : I have the following problem. : In a csv file I have under column A, the date, and column B, the prices. : Thus, for example, the file looks something like this - : : 1/31/04 2.5 : 2/1/042.6 : ... : 4/12/04 3.5 : :