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











up vote
0
down vote

favorite













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 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.



















    up vote
    0
    down vote

    favorite













    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 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.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      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 at 22:48









      Malintha

      1,24862652




      1,24862652




      marked as duplicate by Community Nov 22 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 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

















          up vote
          2
          down vote



          accepted










          use the function nrow()



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





          share|improve this answer




























            up vote
            1
            down vote













            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








              up vote
              2
              down vote



              accepted










              use the function nrow()



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





              share|improve this answer

























                up vote
                2
                down vote



                accepted










                use the function nrow()



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





                share|improve this answer























                  up vote
                  2
                  down vote



                  accepted







                  up vote
                  2
                  down vote



                  accepted






                  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 at 22:54









                  alex_danielssen

                  1096




                  1096
























                      up vote
                      1
                      down vote













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



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





                      share|improve this answer

























                        up vote
                        1
                        down vote













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



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





                        share|improve this answer























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          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 at 23:03









                          neilfws

                          17.5k53648




                          17.5k53648















                              Popular posts from this blog

                              Contact image not getting when fetch all contact list from iPhone by CNContact

                              count number of partitions of a set with n elements into k subsets

                              A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks