For loop and function any

See the FAQ: How to do a minimal reproducible example reprex for beginners for how to solicit more specific answers.

For id a, the three columns will sum to 3, 1, and 3, respectively when using group_by and count after library(dplyr)