我的数据如下
mydata=structure(list(X = structure(c(6L, 6L, 7L, 7L, 8L, 10L, 10L,
10L, 10L, 1L, 1L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 9L,
8L, 8L, 9L, 9L, 9L, 8L, 10L, 8L, 9L, 8L, 8L, 10L, 10L, 10L, 10L,
10L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12"), class = "factor"), Sous_Categorie = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L), .Label = c("o,y", "y"), class = "factor")), .Names = c("X",
"Sous_Categorie"), row.names = c(NA, -86L), class = "data.frame")
我试过这个:cc=count(mydata, c("X", "Sous_Categorie"))
它给了我
X Sous_Categorie freq
1 1 y 2
2 3 y 4
3 4 y 5
4 5 y 26
5 6 o,y 2
6 6 y 16
7 7 o,y 2
8 7 y 7
9 8 o,y 1
10 8 y 6
11 9 y 5
12 10 o,y 4
13 10 y 6
但是我的目标是获取输出:即使没有值,X总是从1到12,nb_freq是X中的出现次数
X o,y o
1 nb_freq nb_freq
.
.
12 nb_freq nb_freq
最简单的方法是什么?感谢
答案 0 :(得分:1)
我们可以使用
%w( about mission path standard getting_started welcome infection instruction implementation )