Thanks to Jean-Paul Fox, Dimitris Rizopoulos,Garfield Brown, Sarah Goslee,
James Holtman ,Sundar Dorai-Raj for helping me to solve the
problem. Given below is my question and their responses.
Catalina
-------- Original Message --------
Subject: RE: [S] find row&col
Date: Wed, 23 Oct 2002 14:57:31 +0200
From: "Fox, G.J.A. (EDTE)" <G.J.A.Fox@edte.utwente.nl>
To: 'Catalina Mesina' <cmesina@cs.vu.nl>
there is a powerful function "which"
m<-matrix(1:12,ncol=3)
then which(m==10) gives the position in m as if m were a vector.
To do a little bit more:
row-number :: which(m == 10) %% nrow(m)
col-number :: floor(which(m == 10)/nrow(m))+1 or
floor(which(m == 10)/nrow(m)) when it was the last element of a column
Jean-Paul Fox
> -----Original Message-----
> From: Catalina Mesina [mailto:cmesina@cs.vu.nl]
> Sent: Wednesday, October 23, 2002 2:47 PM
> To: s-news@lists.biostat.wustl.edu
> Subject: [S] find row&col
>
>
> Dear all,
>
> I have a very simple question.
> Suppose that we have a matrix
>
> m<-matrix(1:12,ncol=3)
> > m
> [,1] [,2] [,3]
> [1,] 1 5 9
> [2,] 2 6 10
> [3,] 3 7 11
> [4,] 4 8 12
>
> Is there any function in Splus that can give me which is the
> line and the column where element 10, for example, is situated?
>
> Catalina
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
|