stats::col
-- select and re-arrange
columns of a samplestats::col
(s, ..)
creates a new sample
from selected columns of the sample s
.
stats::col(s, c1 <, c2, ..>)
stats::col(s, c1..c2 <, c3..c4, ..>)
s |
- | a sample of domain type stats::sample . |
c1, c2, .. |
- | positive integers representing column indices of the
sample s . |
a sample of domain type stats::sample
.
stats::concatCol
,
stats::concatRow
,
stats::row
stats::col
is useful for selecting columns of interest
or for re-arranging columns.s
specified by the remaining arguments
of stats::col
are used to build a new sample. The new
sample contains the columns of s
in the order specified by
the call to stats::col
. Columns can be duplicated by
specifying the column index more than once.The following sample contains columns for ``gender'', ``age'', ``height'', the ``number of yellow socks'' and ``eye color'' of a person:
>> stats::sample([["m", 26, 180, 3, "blue"], ["f", 22, 160, 0, "brown"], ["f", 48, 155, 2, "green"], ["m", 30, 172, 1, "brown"]])
"m" 26 180 3 "blue" "f" 22 160 0 "brown" "f" 48 155 2 "green" "m" 30 172 1 "brown"
Since nobody is really interested in the yellow socks, we create a new sample without that column:
>> stats::col(%, 1..3, 5)
"m" 26 180 "blue" "f" 22 160 "brown" "f" 48 155 "green" "m" 30 172 "brown"
We can use stats::col
to re-arrange the
sample. As an illustrating example, we duplicate the first column:
>> stats::col(%, 1, 3, 2, 1, 4)
"m" 180 26 "m" "blue" "f" 160 22 "f" "brown" "f" 155 48 "f" "green" "m" 172 30 "m" "brown"