[R] Table orderd by frequencies
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Tue Jul 22 10:23:27 CEST 2008
2008/7/22 Kunzler, Andreas <a.kunzler at bzaek.de>:
> Dear List,
>
> I try to order the output of a table by the frequencies of the vector I
> am look at.
>
> The object I am looking at is a factor with a lot of levels that were
> named only once.
>
> Therefore it would be much easier to order the output by the frequencies
> of the levels.
>
> E.g.
>> levels(a)
> "a" "b" "c" "d"
>
> Preferred outcome:
> table(a)
>
> b c a d
> 10 5 1 1
>
Can't you just sort the table:
> set.seed(123)
> a=as.factor(sample(letters[1:4],16,replace=TRUE))
> sort(table(a),dec=TRUE)
a
d b c a
6 4 4 2
Barry
More information about the R-help
mailing list