[R] sort adjacency matrix
Rui Barradas
ruipbarradas at sapo.pt
Mon Apr 6 20:20:02 CEST 2015
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.
>
More information about the R-help
mailing list