Skip to content
Prev 369947 / 398503 Next

Counting with multiple criteria using data table

You should have offered the output of:

 dput(Test)
I count 4 data.tables and a total of 11 items so why only 3 columns and 9 items?

Were you tabulating colors by month?
(Color=="red"&Grade=="F") |
(Color=="orange"&Grade=="F")|
(Color=="orange"&Grade=="F")|
(Color=="red"&Grade=="F") ,        table(Month, Color)]
        Color
Month    green orange red
  April      1      1   1
  August     0      1   1
  June       0      0   1
  May        1      1   0
Rhelp is plain-text. Do read the Posting Guide:

Another possibility:

 Test[(Color=="green"&Grade=="A") |    These are the conditions separated by logical OR's in the first argument to `[data.table`
      (Color=="red"&Grade=="F") |
      (Color=="orange"&Grade=="F")|
      (Color=="orange"&Grade=="F")|
      (Color=="red"&Grade=="F") ,          table(Month, Grade)]


        Grade
Month    A F
  April  1 2
  August 0 2
  June   0 1
  May    1 1
David Winsemius
Alameda, CA, USA