Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20131120/850e45dc/attachment.pl>
To transform an adjacency matrix
4 messages · Arnaud Michel, Pascal Oettli, David L Carlson
Hello, One approach is: m <- structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L)) out <- which(m==1, arr.ind=TRUE) out[order(out[,1]),] Regards, Pascal
On 20 November 2013 19:28, Arnaud Michel <michel.arnaud at cirad.fr> wrote:
Hi
I have the following problem
I would like to build, from a matrix filled with 0 and with 1, a matrix
or a data.frame which contains, in every line, the number of the line
and the number of the column of the matrix for which the value is equal
to 1.
Exemple :
dput(m)
structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,
0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L))
Result
1 5
2 3
2 4
4 1
4 3
Thank you for your help
--
Michel ARNAUD
Charg? de mission aupr?s du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31
[[alternative HTML version deleted]]
______________________________________________ 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.
Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan
Thank you Pascal Its fine Michel Le 20/11/2013 11:55, Pascal Oettli a ?crit :
Hello, One approach is: m <- structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L)) out <- which(m==1, arr.ind=TRUE) out[order(out[,1]),] Regards, Pascal On 20 November 2013 19:28, Arnaud Michel <michel.arnaud at cirad.fr> wrote:
Hi
I have the following problem
I would like to build, from a matrix filled with 0 and with 1, a matrix
or a data.frame which contains, in every line, the number of the line
and the number of the column of the matrix for which the value is equal
to 1.
Exemple :
dput(m)
structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1,
0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L))
Result
1 5
2 3
2 4
4 1
4 3
Thank you for your help
--
Michel ARNAUD
Charg? de mission aupr?s du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31
[[alternative HTML version deleted]]
______________________________________________ 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.
Michel ARNAUD Charg? de mission aupr?s du DRH DGDRD-Drh - TA 174/04 Av Agropolis 34398 Montpellier cedex 5 tel : 04.67.61.75.38 fax : 04.67.61.57.87 port: 06.47.43.55.31
indx <- arrayInd(which(m>0), .dim=c(5, 5)) indx
[,1] [,2] [1,] 4 1 [2,] 2 3 [3,] 4 3 [4,] 2 4 [5,] 1 5 # If you want the result sorted
indx[order(indx[,1], indx[,2]),]
[,1] [,2] [1,] 1 5 [2,] 2 3 [3,] 2 4 [4,] 4 1 [5,] 4 3 ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Arnaud Michel Sent: Wednesday, November 20, 2013 4:29 AM To: R help Subject: [R] To transform an adjacency matrix Hi I have the following problem I would like to build, from a matrix filled with 0 and with 1, a matrix or a data.frame which contains, in every line, the number of the line and the number of the column of the matrix for which the value is equal to 1. Exemple : dput(m) structure(c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0), .Dim = c(5L, 5L)) Result 1 5 2 3 2 4 4 1 4 3 Thank you for your help
Michel ARNAUD Chargi de mission auprhs du DRH DGDRD-Drh - TA 174/04 Av Agropolis 34398 Montpellier cedex 5 tel : 04.67.61.75.38 fax : 04.67.61.57.87 port: 06.47.43.55.31 [[alternative HTML version deleted]]