Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-20 Thread PIKAL Petr
ll probably have to be a matrix of characters. There you go from > a 3×4 matrix to a 3×2 matrix. What do you want in case of Barts 2×2 > matrix? A 3×1 or 1×3 matrix? And in a more general case? > > Best regards > > Frede > > > Sendt fra Samsung mobil > > Oprindelig

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread Frede Aakmann Tøgersen
delig meddelelse Fra: carol white Dato:19/06/2014 15.18 (GMT+01:00) Til: Bart Kastermans Cc: r-help@r-project.org Emne: Re: [R] extract a subset of non-contiguous elements of a matrix tm.1=rbind(c(1,-3,2,-4), c(1,-3,2,-4),c(1,-3,2,-4)) > which(tm.1 > 0, arr.ind=TRUE) row col [1,

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread carol white
e Dato:19/06/2014 15.18 (GMT+01:00) Til: Bart Kastermans Cc: r-help@r-project.org Emne: Re: [R] extract a subset of non-contiguous elements of a matrix  tm.1=rbind(c(1,-3,2,-4), c(1,-3,2,-4),c(1,-3,2,-4)) > which(tm.1 > 0, arr.ind=TRUE)      row col [1,]   1   1 [2,]   2  

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread Frede Aakmann Tøgersen
15.18 (GMT+01:00) Til: Bart Kastermans Cc: r-help@r-project.org Emne: Re: [R] extract a subset of non-contiguous elements of a matrix tm.1=rbind(c(1,-3,2,-4), c(1,-3,2,-4),c(1,-3,2,-4)) > which(tm.1 > 0, arr.ind=TRUE) row col [1,] 1 1 [2,] 2 1 [3,] 3 1 [4,] 1 3 [5,] 2

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread Bart Kastermans
On 19 Jun 2014, at 15:16, carol white wrote: > tm.1=rbind(c(1,-3,2,-4), c(1,-3,2,-4),c(1,-3,2,-4)) > > > which(tm.1 > 0, arr.ind=TRUE) > row col > [1,] 1 1 > [2,] 2 1 > [3,] 3 1 > [4,] 1 3 > [5,] 2 3 > [6,] 3 3 > > so the answer should have the elements of tm.1 wi

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread carol white
 tm.1=rbind(c(1,-3,2,-4), c(1,-3,2,-4),c(1,-3,2,-4)) > which(tm.1 > 0, arr.ind=TRUE)      row col [1,]   1   1 [2,]   2   1 [3,]   3   1 [4,]   1   3 [5,]   2   3 [6,]   3   3 so the answer should have the elements of tm.1 with the following indexes 1,1 1,3 2,1 2,3 3

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread Bart Kastermans
If you give an example of input and desired output I can think about this. But at this point I do not understand what you want. In the example I gave the positive elements do not form a submatrix in any way I can think of. On 19 Jun 2014, at 15:04, carol white wrote: > well it gives a vector

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread peter dalgaard
This _was_ in the answer you got, but to clarify things, perhaps try this: (M <- matrix(1:9,3,3)) (ix <- rbind(c(3,2),c(1,3))) M[3,2] M[1,3] M[ix] -pd On 19 Jun 2014, at 14:12 , carol white wrote: > The extracted values don't form a matrix and that's the question how to > extract because whic

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread carol white
The extracted values don't form a matrix and that's the question how to extract because which returns the indexes? that is, from 1,1 2,1 1,2 how to retrieve values? Or if at the position 2,1, there is a negative value, how to retrieve 1,1 1,2 Carol On Thursday, June 19, 2014 1:29 PM, Bart

Re: [R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread Bart Kastermans
On 19 Jun 2014, at 13:19, carol white wrote: > Hi, > Is there a way to extract a subset of non-contiguous elements of a matrix > elegantly and with 1 or very few scripts? > > Suppose I have a matrix of positive and negative numbers (m) and I want to > retrieve only the positive number. This I

[R] extract a subset of non-contiguous elements of a matrix

2014-06-19 Thread carol white
Hi, Is there a way to extract a subset of non-contiguous elements of a matrix elegantly and with 1 or very few scripts? Suppose I have a matrix of positive and negative numbers (m) and I want to retrieve only the positive number. This I can do which(m>0, arr.ind=T) which gives the indices of po