计算重复变量中的出现次数(r)

时间:2015-06-13 12:49:22

标签: r count summary

我需要总结人们在一周内工作的天数。 每个变量代表一天。

我需要提供工作天数的摘要。

我不太清楚这样做的方便方式(除了每天总结表格之外)。

有什么建议吗?

data = structure(list(ACTWKDY1 = structure(c(2L, NA, 6L, 9L, 2L, 2L, 
                                  2L, NA, 2L, 3L), .Label = c("Friday", "Monday", "Not working at all", 
                                                              "Saturday", "Scheduled working days not relevant", "Sunday", 
                                                              "Thursday", "Tuesday", "Wednesday"), class = "factor"), ACTWKDY2 = structure(c(6L, 
                                                                                                                                             NA, 2L, 5L, 6L, 6L, 6L, NA, 6L, NA), .Label = c("Friday", "Monday", 
                                                                                                                                                                                             "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"), class = "factor"), 
           ACTWKDY3 = structure(c(7L, NA, 6L, 1L, 7L, 5L, 7L, NA, 7L, 
                                  NA), .Label = c("Friday", "Monday", "Saturday", "Sunday", 
                                                  "Thursday", "Tuesday", "Wednesday"), class = "factor"), ACTWKDY4 = structure(c(5L, 
                                                                                                                                 NA, 7L, 3L, 5L, 1L, 5L, NA, 5L, NA), .Label = c("Friday", 
                                                                                                                                                                                 "Monday", "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"
                                                                                                                                 ), class = "factor"), ACTWKDY5 = structure(c(1L, NA, 5L, 
                                                                                                                                                                              4L, 1L, 3L, 1L, NA, 1L, NA), .Label = c("Friday", "Monday", 
                                                                                                                                                                                                                      "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"), class = "factor"), 
           ACTWKDY6 = structure(c(NA_integer_, NA_integer_, NA_integer_, 
                                  NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                  NA_integer_, NA_integer_), .Label = c("Friday", "Monday", 
                                                                        "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"), class = "factor"), 
           ACTWKDY7 = structure(c(NA_integer_, NA_integer_, NA_integer_, 
                                  NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                  NA_integer_, NA_integer_), .Label = c("Friday", "Monday", 
                                                                        "Saturday", "Sunday", "Thursday", "Wednesday"), class = "factor")), row.names = c(NA, 
                                                                                                                                                          10L), class = "data.frame", .Names = c("ACTWKDY1", "ACTWKDY2", 
                                                                                                                                                                                                 "ACTWKDY3", "ACTWKDY4", "ACTWKDY5", "ACTWKDY6", "ACTWKDY7"))


             ACTWKDY1 ACTWKDY2  ACTWKDY3  ACTWKDY4 ACTWKDY5 ACTWKDY6 ACTWKDY7
              Monday  Tuesday Wednesday  Thursday   Friday     <NA>     <NA>
                <NA>     <NA>      <NA>      <NA>     <NA>     <NA>     <NA>
              Sunday   Monday   Tuesday Wednesday Thursday     <NA>     <NA>
           Wednesday Thursday    Friday  Saturday   Sunday     <NA>     <NA>
              Monday  Tuesday Wednesday  Thursday   Friday     <NA>     <NA>
              Monday  Tuesday  Thursday    Friday Saturday     <NA>     <NA>
              Monday  Tuesday Wednesday  Thursday   Friday     <NA>     <NA>
                <NA>     <NA>      <NA>      <NA>     <NA>     <NA>     <NA>
              Monday  Tuesday Wednesday  Thursday   Friday     <NA>     <NA>
 Not working at all     <NA>      <NA>      <NA>     <NA>     <NA>     <NA>

1 个答案:

答案 0 :(得分:1)

这样的事情会有意义吗?

table(unlist(data))

View(table(unlist(data)))

Var1                                Freq
Friday                              6
Monday                              6
Not working at all                  1
Saturday                            2
Scheduled working days not relevant 0
Sunday                              2
Thursday                            7
Tuesday                             6
Wednesday                           6