I wanna get the count of occurrences when the data in column 1 is 1 and also data in column 2 is 1. TIA

I wanna get the count of occurrences when the data in column 1 is 1 and also data in column 2 is 1. TIA

You can use filter and summarize from dplyr package
library(dplyr)
df1 <- df %>%
filter(col1 == 1 & col2==1) %>%
summarize(Freq_col1andcol2_equalto1 = n())
data:
df <- tribble(
~col1, ~col2,
5,5,
5,5,
1,1,
5,5,
5,5)
seed(323)
df <- tibble(x = round(runif(100, 0, 10)),
y = round(runif(100, 0, 10)))
df %>% count(x==1,y==1)
# A tibble: 4 x 3
# `x == 1` `y == 1` n
# <lgl> <lgl> <int>
# 1 FALSE FALSE 80
# 2 FALSE TRUE 10
# 3 TRUE FALSE 8
# 4 TRUE TRUE 2
In this scenario, the first column gets 10 times number 1 (8 alone and 2 together with the second column), and the second column gets 12 times (10 alone and 2 together with the first column)