Count elements (rows) in group of a data table [duplicate]












0
















This question already has an answer here:




  • Count number of rows matching a criteria

    6 answers




I have table (dt) which has several columns.



  X__1 First Name  Last Name Gender       Country Age       Date   Id
1: 1 Dulce Abril Female United States 32 15/10/2017 1562
2: 2 Mara Hashimoto Female Great Britain 25 16/08/2016 1582
3: 3 Philip Gent Male France 36 21/05/2015 2587
4: 4 Kathleen Hanner Female United States 25 15/10/2017 3549
5: 5 Nereida Magwood Female United States 58 16/08/2016 2468


I want to count the number of rows which has Country = "France" and Age >32.



I used the following command which gives me the result, but i need to count the number of rows in the result. What is the command to do it?



dt[Country == 'France' & Age > 32]









share|improve this question













marked as duplicate by Community Nov 22 '18 at 9:45


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • Count number of rows matching a criteria

      6 answers




    I have table (dt) which has several columns.



      X__1 First Name  Last Name Gender       Country Age       Date   Id
    1: 1 Dulce Abril Female United States 32 15/10/2017 1562
    2: 2 Mara Hashimoto Female Great Britain 25 16/08/2016 1582
    3: 3 Philip Gent Male France 36 21/05/2015 2587
    4: 4 Kathleen Hanner Female United States 25 15/10/2017 3549
    5: 5 Nereida Magwood Female United States 58 16/08/2016 2468


    I want to count the number of rows which has Country = "France" and Age >32.



    I used the following command which gives me the result, but i need to count the number of rows in the result. What is the command to do it?



    dt[Country == 'France' & Age > 32]









    share|improve this question













    marked as duplicate by Community Nov 22 '18 at 9:45


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • Count number of rows matching a criteria

        6 answers




      I have table (dt) which has several columns.



        X__1 First Name  Last Name Gender       Country Age       Date   Id
      1: 1 Dulce Abril Female United States 32 15/10/2017 1562
      2: 2 Mara Hashimoto Female Great Britain 25 16/08/2016 1582
      3: 3 Philip Gent Male France 36 21/05/2015 2587
      4: 4 Kathleen Hanner Female United States 25 15/10/2017 3549
      5: 5 Nereida Magwood Female United States 58 16/08/2016 2468


      I want to count the number of rows which has Country = "France" and Age >32.



      I used the following command which gives me the result, but i need to count the number of rows in the result. What is the command to do it?



      dt[Country == 'France' & Age > 32]









      share|improve this question















      This question already has an answer here:




      • Count number of rows matching a criteria

        6 answers




      I have table (dt) which has several columns.



        X__1 First Name  Last Name Gender       Country Age       Date   Id
      1: 1 Dulce Abril Female United States 32 15/10/2017 1562
      2: 2 Mara Hashimoto Female Great Britain 25 16/08/2016 1582
      3: 3 Philip Gent Male France 36 21/05/2015 2587
      4: 4 Kathleen Hanner Female United States 25 15/10/2017 3549
      5: 5 Nereida Magwood Female United States 58 16/08/2016 2468


      I want to count the number of rows which has Country = "France" and Age >32.



      I used the following command which gives me the result, but i need to count the number of rows in the result. What is the command to do it?



      dt[Country == 'France' & Age > 32]




      This question already has an answer here:




      • Count number of rows matching a criteria

        6 answers








      r






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 22:48









      MalinthaMalintha

      1,33962653




      1,33962653




      marked as duplicate by Community Nov 22 '18 at 9:45


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Community Nov 22 '18 at 9:45


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          2 Answers
          2






          active

          oldest

          votes


















          2














          use the function nrow()



          nrow(dt[Country == 'France' & Age > 32])





          share|improve this answer































            1














            nrow() is simplest, but if you want to do it using data.table syntax:



            dt[Country == 'France' & Age > 32, (.N)]





            share|improve this answer






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              use the function nrow()



              nrow(dt[Country == 'France' & Age > 32])





              share|improve this answer




























                2














                use the function nrow()



                nrow(dt[Country == 'France' & Age > 32])





                share|improve this answer


























                  2












                  2








                  2







                  use the function nrow()



                  nrow(dt[Country == 'France' & Age > 32])





                  share|improve this answer













                  use the function nrow()



                  nrow(dt[Country == 'France' & Age > 32])






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 22:54









                  alex_danielssenalex_danielssen

                  1096




                  1096

























                      1














                      nrow() is simplest, but if you want to do it using data.table syntax:



                      dt[Country == 'France' & Age > 32, (.N)]





                      share|improve this answer




























                        1














                        nrow() is simplest, but if you want to do it using data.table syntax:



                        dt[Country == 'France' & Age > 32, (.N)]





                        share|improve this answer


























                          1












                          1








                          1







                          nrow() is simplest, but if you want to do it using data.table syntax:



                          dt[Country == 'France' & Age > 32, (.N)]





                          share|improve this answer













                          nrow() is simplest, but if you want to do it using data.table syntax:



                          dt[Country == 'France' & Age > 32, (.N)]






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 21 '18 at 23:03









                          neilfwsneilfws

                          18.1k53749




                          18.1k53749















                              Popular posts from this blog

                              MongoDB - Not Authorized To Execute Command

                              How to fix TextFormField cause rebuild widget in Flutter

                              in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith