df <- data.frame(
A = c("Y","N","Y","Y","N","Y","Y","N","N","N","Y","Y","N"),
B = c(1,3,2,3,1,2,2,3,1,3,1,2,3)
)
df
A B
1 Y 1
2 N 3
3 Y 2
4 Y 3
5 N 1
6 Y 2
7 Y 2
8 N 3
9 N 1
10 N 3
11 Y 1
12 Y 2
13 N 3
I need to test this dataframe and find out if, for a given value of column B (1,2, or 3), what is the sum of all the Y's and what is the sum of all the N's.
like, "If B ==1, what is the sum of Y" and "If B == 1, what is the sum of N"
What I really need to do is find out if the sum of N or Y == 0 while column B = (1,2,3)
For instance, when B = 1, the sum of Y's is 2, and the Sum of N's is 2.
I intentionally left out a N when B = 2. So the sum of N when B = 2 is 0. How do I ask the dataframe this question?
Thanks I am lost on this one