I'm trying to get the sum
of n
from a count
table. I'm able to do this with this:
mtcars %>%
count(cyl) %>%
pull(n) %>%
sum()
Is there a one-line way to do this in base R. The purpose of the value is to add this as a caption on a table like this:
mtcars %>%
count(cyl) %>%
kable(caption = "n = (insert value here")
I actually want to count the total of the n because in my real pipe workflow I filter the data frame.
mtcars %>%
filter(vs == 1) %>%
count(cyl)
# cyl n
# 1 4 10
# 2 6 4
In this case, I would like it to be 14 (10+4) which is the sum of n
and not 32.
Something like this solution: Temporarily store variable in series of pipes dplyr