[R] ordering a vector

jim holtman jholtman at gmail.com
Fri Jan 21 21:39:50 CET 2011


look at 'order'

yourMatrix[order(yourMatrix[, 'yourCol']), ]

On Fri, Jan 21, 2011 at 2:38 PM, Francesco Petrogalli
<francesco.petrogalli at gmail.com> wrote:
> Hi,
> is there a R function that order a matrix according to some criteria
> based on the rows(or cols) of that matrix?
>
> For example, let's say that my matrix S is composed by n rows S_1,
> S_2,.., S_n and that I compute some real value g_i=g(S_i) for each
> row.
> Then I want to order this set of g_i (from smaller to bigger) and
> order the correspondent row to the new position.
>
> Is it possible (apart from looping on the index) to do this with some
> predefined R function?
>
> Thanks,
>
> Francesco
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list