Previous Page Next Page Contents

stats::sortSample -- sort the rows of a sample

Introduction

stats::sortSample(s, ..) sorts the rows of the sample s.

Call(s)

stats::sortSample(s)
stats::sortSample(s, c1, c2, ..)
stats::sortSample(s, [c1, c2, ..])

Parameters

s - a sample of domain type stats::sample.
c1, c2, .. - integers representing column indices of the sample s.

Returns

a sample of domain type stats::sample.

Related Functions

stats::selectRow

Details

Example 1

We create a sample with one column and sort it:

>> stats::sortSample(stats::sample([x, g2, 3, g1, 8/5, 2]))
   
                                     x
                                    g1
                                    g2
                                   8/5
                                     2
                                     3
      

Example 2

We create a sample with two columns:

>> stats::sample([[b, 2], [a, 5], [a, 2], [c, 1], [b, 3]])
   
                                  b  2
                                  a  5
                                  a  2
                                  c  1
                                  b  3
      

Note the different sorting priorities specified by the column indices:

>> stats::sortSample(%, 1), stats::sortSample(%, 2),
   stats::sortSample(%, 1, 2), stats::sortSample(%, 2, 1)
   
                      a  2  , c  1  , a  2  , c  1
                      a  5    a  2    a  5    a  2
                      b  3    b  2    b  2    b  2
                      b  2    b  3    b  3    b  3
                      c  1    a  5    c  1    a  5
      

Example 3

We create a sample containing income and costs in the years 1997 and 1998:

>> stats::sample([[123, "costs", "97"], [720, "income", "98"],
                  [623, "income", "97"], [150, "costs", "98"]])
   
                           123  "costs"   "97"
                           720  "income"  "98"
                           623  "income"  "97"
                           150  "costs"   "98"
      

We sort according to the year (third column):

>> stats::sortSample(%, 3)
   
                           623  "income"  "97"
                           123  "costs"   "97"
                           150  "costs"   "98"
                           720  "income"  "98"
      

We sort with priority on the year. Items of the same year are then sorted lexicographically (``costs'' before ``income''):

>> stats::sortSample(%2, 3, 2)
   
                           123  "costs"   "97"
                           623  "income"  "97"
                           150  "costs"   "98"
                           720  "income"  "98"
      

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000