I have a dataframe with different counts of 1
in each column, like this:
dat <-
data.frame('col1' = rep(c(0, 1), 6),
'col2' = rep(c(0:2), 4),
'col3' = rep(c(0:3), 3))
I'm trying to use dplyr::summarise_each
to do the following programatically:
dat_new <-
data.frame(tally(dat, col1 == 1), # or count()
tally(dat, col2 == 1),
tally(dat, col3 == 1))
to give, for each column, counts of where the condition rowvalue == 1
are met (in this case, 6, 4, and 3, respectively). However, I'm really struggling trying to do something that I think should be very easy, I would assume using dplyr::summarise_each()
. All the help I've found online usually requires some pre-grouping, but that's not necessary in this case. Many thanks for your help