4.1 A specific example
======================
Suppose, for example, we have a sample of 30 tax accountants from all
the states and territories of Australia(1) and their individual state of
origin is specified by a character vector of state mnemonics as
> state <- c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa",
"qld", "vic", "nsw", "vic", "qld", "qld", "sa", "tas",
"sa", "nt", "wa", "vic", "qld", "nsw", "nsw", "wa",
"sa", "act", "nsw", "vic", "vic", "act")
Notice that in the case of a character vector, "sorted" means sorted
in alphabetical order.
A _factor_ is similarly created using the 'factor()' function:
> statef <- factor(state)
The 'print()' function handles factors slightly differently from
other objects:
> statef
[1] tas sa qld nsw nsw nt wa wa qld vic nsw vic qld qld sa
[16] tas sa nt wa vic qld nsw nsw wa sa act nsw vic vic act
Levels: act nsw nt qld sa tas vic wa
To find out the levels of a factor the function 'levels()' can be
used.
> levels(statef)
[1] "act" "nsw" "nt" "qld" "sa" "tas" "vic" "wa"
- The function tapply() and ragged arrays
- Ordered factors
---------- Footnotes ----------
(1) Readers should note that there are eight states and territories
in Australia, namely the Australian Capital Territory, New South Wales,
the Northern Territory, Queensland, South Australia, Tasmania, Victoria
and Western Australia.
automatically generated by info2www version 1.2.2.9