Hello, You should have used ?dput to post your data example. Since you haven't, I've made up one. set.seed(4795) mat <- matrix(sample(0:1, 24, replace = TRUE), nrow = 6) mat inx <- order(rowSums(mat), decreasing = TRUE) mat[inx, ] Hope this helps, Rui Barradas Em 06-04-2015 18:18, Ragia Ibrahim escreveu:> Dear group > i have the following matrix > > 1 . . 1 . . 1 . . . . > 2 . . . . . . 1 . . . > 3 1 . . . 1 . . 1 . 1 > 4 . . . . . 1 . . . . > 5 . . 1 . . . . . . 1 > 6 1 . . 1 . . . . 1 . > 7 . 1 . . . . . 1 . . > 8 . . 1 . . . 1 . . 1 > 9 . . . . . 1 . . . 1 > 10 . . 1 . 1 . . 1 1 . > > I want to sort it according to ones in each row ascending (where max number of ones first) > > to be as follow > > 3 1 . . . 1 . . 1 . 1 > 10 . . 1 . 1 . . 1 1 . > 6 1 . . 1 . . . . 1 .8 . . 1 . . . 1 . . 11 . . 1 . . 1 . . . .5 . . 1 . . . . . . 17 . 1 . . . . . 1 . .9 . . . . . 1 . . . 12 . . . . . . 1 . . .4 . . . . . 1 . . . . > > how can I do this in R > thanks in advance > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >
Hi again the data represents a directed graph represented in a matrix e.g library(igraph) g <- forest.fire.game(10, fw.prob=0.3 , bw.factor=0.32/0.3, directed = TRUE) m=get.adjacency(g , attr=NULL) print(m) ---------- many thanks and pardon me for multiple posts Ragia> Date: Mon, 6 Apr 2015 19:20:02 +0100 > From: ruipbarradas at sapo.pt > To: ragia11 at hotmail.com; r-help at r-project.org > Subject: Re: [R] sort adjacency matrix > > Hello, > > You should have used ?dput to post your data example. > Since you haven't, I've made up one. > > set.seed(4795) > mat <- matrix(sample(0:1, 24, replace = TRUE), nrow = 6) > mat > > inx <- order(rowSums(mat), decreasing = TRUE) > mat[inx, ] > > > Hope this helps, > > Rui Barradas > > Em 06-04-2015 18:18, Ragia Ibrahim escreveu: > > Dear group > > i have the following matrix > > > > 1 . . 1 . . 1 . . . . > > 2 . . . . . . 1 . . . > > 3 1 . . . 1 . . 1 . 1 > > 4 . . . . . 1 . . . . > > 5 . . 1 . . . . . . 1 > > 6 1 . . 1 . . . . 1 . > > 7 . 1 . . . . . 1 . . > > 8 . . 1 . . . 1 . . 1 > > 9 . . . . . 1 . . . 1 > > 10 . . 1 . 1 . . 1 1 . > > > > I want to sort it according to ones in each row ascending (where max number of ones first) > > > > to be as follow > > > > 3 1 . . . 1 . . 1 . 1 > > 10 . . 1 . 1 . . 1 1 . > > 6 1 . . 1 . . . . 1 .8 . . 1 . . . 1 . . 11 . . 1 . . 1 . . . .5 . . 1 . . . . . . 17 . 1 . . . . . 1 . .9 . . . . . 1 . . . 12 . . . . . . 1 . . .4 . . . . . 1 . . . . > > > > how can I do this in R > > thanks in advance > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > >[[alternative HTML version deleted]]
Dear group kindly I have a logical data type ISINFCluster: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 15 16 17 18 19 20 21 22 23 24 25 26 27 28 FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE 29 30 31 32 33 34 35 36 37 38 39 40 41 42 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 43 44 45 46 47 48 49 50 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE and I want to get just number of records from those that has the value true, thus firstclass<- all[ISINCluster] where all is numeric object 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 1 1 2 1 3 1 1 2 5 4 1 6 8 1 2 1 3 3 2 13 1 4 2 4 7 1 14 1 1 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 1 1 2 2 1 1 2 2 2 9 3 1 1 3 6 1 4 1 3 9 2 the firstclass containes the following firstclass 20 27 13 14 And I could not get the first row.. head(firstclass) 20 27 13 14 how can I got it? thanks in advance Ragia [[alternative HTML version deleted]]