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]
r
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.
add a comment |
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]
r
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.
add a comment |
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]
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 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.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
add a comment |
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)]
add a comment |
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])
add a comment |
up vote
2
down vote
accepted
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
use the function nrow()
nrow(dt[Country == 'France' & Age > 32])
answered Nov 21 at 22:54
alex_danielssen
1096
1096
add a comment |
add a comment |
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)]
add a comment |
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)]
add a comment |
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)]
nrow()
is simplest, but if you want to do it using data.table
syntax:
dt[Country == 'France' & Age > 32, (.N)]
answered Nov 21 at 23:03
neilfws
17.5k53648
17.5k53648
add a comment |
add a comment |