Hi all,
I'm trying to get the number of observations for a specific variable after using dplyr::group_by()
df %>%
group_by(country, year) %>%
summarise(mean = mean(variable, na.rm = T),
sd = sd(variable, na.rm = T),
N = n()) -> df2
The idea is to get the count of observations of the variable "variable" for each "country" and "year" to compute some standard errors and some nice confidence intervals. I believe in the code above I'm getting the count of all observations in a country in a specific year, but because "variable" has some NA it isn't what I need for the computation of SE and CI. If it clarifies further my question: I think the n()
above isn't using the same figure as the one used by mean()
, the one I need.
I've tried add_count()
to no avail. What would you suggest? Thanks!