[R] ordering a vector
peter.langfelder at gmail.com
Fri Jan 21 21:42:06 CET 2011
I think you want the following, assuming you defined your function g():
gValues = apply(S, 1, g);
Sordered = S[order(gValues), ]
On Fri, Jan 21, 2011 at 11:38 AM, Francesco Petrogalli
<francesco.petrogalli at gmail.com> wrote:
> 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
> 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?
> R-help at r-project.org mailing list
> 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