[R] Sort or Permutate

Bert Gunter gunter.berton at gene.com
Tue Sep 11 17:48:27 CEST 2012


Ah, but note that the OP's 2nd column is character, not numeric... And
we don't know what the "struct" is (a matrix or data frame?? --does
the OP know the difference?). Has Alaios perused "An Introduction to
R" where he/she might have gained some enlightenment that would have
obviated the need to post?

-- Bert

On Tue, Sep 11, 2012 at 8:00 AM, Berend Hasselman <bhh at xs4all.nl> wrote:
>
> On 11-09-2012, at 13:13, Alaios wrote:
>
>> Dear all,
>> I am having a struct that contains on the first column file names and on the second column a number which is a "rating" of the file on first column
>>
>> A small subset looks like that
>>
>> small
>>      [,1]
>> [1,] "/storage/storage0/59Off.Rtable"
>> [2,] "/storage/storage0/5912On.Rtable"
>> [3,] "/storage/storage0/5912314ff.Rtable"
>>      [,2]
>> [1,] "0.220386301811093"
>> [2,] "0.405237035258638"
>> [3,] "0.288659374128626"
>>
>>
>> I want based on the values of column two to rearrange table elements by keeping though the row elements together.
>> For example if I order those in ascending order should look like
>>
>> small
>>
>> [,1]
>> [1,] "/storage/storage0/59Off.Rtable"
>> [2,] "/storage/storage0/5912314ff.Rtable"
>> [3,] " /storage/storage0/5912On.Rtable"
>>
>>      [,2]
>> [1,] "0.220386301811093"
>> [2,] "0.288659374128626"
>> [3,] "0.405237035258638"
>>
>> I have tried with sort, sort.list and order but I have failed .
>> I do not quite undestand how one can complete this task in R.
>> Could you please spend some time helping me?
>
>
> Please provide data using dput.
> You can do it using order() like this
>
> small <- data.frame(file.name=c(
>  "/storage/storage0/59Off.Rtable",
>  "/storage/storage0/5912On.Rtable",
>  "/storage/storage0/5912314ff.Rtable"), stringsAsFactors=FALSE,
>  value=c(
>  0.220386301811093,
>  0.405237035258638,
>  0.288659374128626)
>  )
>
> v.index <- order(small[,"value"])
> small <- small[v.index,]
> small
>
> Berend
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm




More information about the R-help mailing list