Count number of occurences in repeated variables (r)

74 views Asked by At

I need to summarise the number of days that people have worked during a week. Each variables represent a day.

I need to produce a summary of the number of days worked.

I am not quite sure what would be a convenient manner to do it (beside summing the table for each day).

Any suggestions ?

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

There are 1 answers

0
dimitris_ps On BEST ANSWER

Would something like this make sense?

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