stats::sortSample
-- sort the
rows of a samplestats::sortSample
(s, ..)
sorts the rows of
the sample s
.
stats::sortSample(s)
stats::sortSample(s, c1, c2, ..)
stats::sortSample(s, [c1, c2, ..])
s |
- | a sample of domain type stats::sample . |
c1, c2, .. |
- | integers representing column indices of the sample
s . |
a sample of domain type stats::sample
.
sort
command. Identifiers come first,
numbers second.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
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
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"