Thanks to James and Phil and Peter for their helpful suggestions. I think
that I should also point out one way *not* to do the job:
> xtabs(Count ~ Education + Age_Group, data=educ)
Age_Group
Education>64 25-34 35-44 45-54 55-64
CompletedHS 7558 16431 1855 9435 8795
James Reilly wrote:
> Using reorder.factor from the stats package seems to work:
>
> educ$ed <- reorder(educ$Education, sort(rep(1:4,5)))
> levels(educ$Education)
> [1] "CompletedHS" "IncompleteHS" "Uni1-3" "Uni4+"
> levels(educ$ed)
> [1] "IncompleteHS" "CompletedHS" "Uni1-3" "Uni4+"
Using reorder.factor from the stats package seems to work:
educ$ed <- reorder(educ$Education, sort(rep(1:4,5)))
levels(educ$Education)
[1] "CompletedHS" "IncompleteHS" "Uni1-3" "Uni4+"
levels(educ$ed)
[1] "IncompleteHS" "CompletedHS" "Uni1-3" "Uni4+"
xtabs(Count ~ ed + Age_Group, d
A small example before I begin my query:
> educ <- read.table(efile, header=TRUE)
> educ
Education Age_Group Count
1 IncompleteHS 25-34 5416
2 IncompleteHS 35-44 5030
3 IncompleteHS 45-54 5777
4 IncompleteHS 55-64 7606
5 IncompleteHS >64 13746
6 CompletedHS
4 matches
Mail list logo