R语言 -- table() 函数对数据进行频数统计

> vector <- c(rep("a", 1), rep("c", 2), rep("d", 3), rep("b", 4)); vector
 [1] "a" "c" "c" "d" "d" "d" "b" "b" "b" "b"
> count = as.data.frame(table(vector)); sorted
  vector Freq
1      a    1
2      b    4
3      c    2
4      d    3
> 
> # 按频度正序排列
> count_increasing = count[order(count[, 2]),]; count_increasing 
  vector Freq
1      a    1
3      c    2
4      d    3
2      b    4
> 
> # 按频度倒序排列
> count_decreasing = count[order(count[, 2], decreasing=TRUE),]; count_decreasing 
  vector Freq
2      b    4
4      d    3
3      c    2
1      a    1

你可能感兴趣的:(R语言 -- table() 函数对数据进行频数统计)