I have a data frame and want to count the number of zeros in each row using dplyr's rowwise. What am I doing wrong?
dt2 = data.frame(A = c(8, 6), B = c(0, 0), C = c(0, 5))
dt2
zerocount <- function(x) {sum(x == 0)}
library(dplyr)
dt2 %>% rowwise() %>% mutate(nr_of_0s = zerocount(A, B, C))
The code above works if I replace zerocount(A, B, C) in the line above with, for example, max(A, B, C). What is wrong? Thank you!