Count elements (rows) in group of a data table [duplicate]
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]
r
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.
add a comment |
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]
r
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.
add a comment |
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]
r
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
r
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.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
add a comment |
nrow()
is simplest, but if you want to do it using data.table
syntax:
dt[Country == 'France' & Age > 32, (.N)]
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
add a comment |
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
add a comment |
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
answered Nov 21 '18 at 22:54
alex_danielssenalex_danielssen
1096
1096
add a comment |
add a comment |
nrow()
is simplest, but if you want to do it using data.table
syntax:
dt[Country == 'France' & Age > 32, (.N)]
add a comment |
nrow()
is simplest, but if you want to do it using data.table
syntax:
dt[Country == 'France' & Age > 32, (.N)]
add a comment |
nrow()
is simplest, but if you want to do it using data.table
syntax:
dt[Country == 'France' & Age > 32, (.N)]
nrow()
is simplest, but if you want to do it using data.table
syntax:
dt[Country == 'France' & Age > 32, (.N)]
answered Nov 21 '18 at 23:03
neilfwsneilfws
18.1k53749
18.1k53749
add a comment |
add a comment |