Hi all,
I am new into R studio and I want to count the number of rows that meet conditions in two columns. let's say I have a dataset something like :
df <- data.frame(stringsAsFactors = FALSE,
A = c("X", "Y", "X", "X", "Z"),
B = c(0, 1, 0, 0, 1),
C = c("AD2758", "AD2758", "AD2764", "AD2768", "AD2772")
)
I want to count those Xs in the first column which the number in the next row in the second column is 1. So it should count Xs in the first and fourth rows, but it should not count the X in the third row.
Any advice would be greatly appreciated.