Running R 4.0.2 and dplyr 1.0.2
I am trying to use n = n()
in a summarize call on a srvyr object:
relduration_by_age_grp <- l %>%
filter(ongoing == 0 & ptype == i) %>%
select(ego.id, ptype, age.grp, ego.age.grp, duration, ego.wawt) %>%
mutate(min.age.grp = ifelse(age.grp < ego.age.grp,
age.grp,
ego.age.grp)) %>%
srvyr::as_survey(ids=1, weights=ego.wawt) %>%
group_by(ptype, min.age.grp) %>%
summarize(n = n(),
wtd.median = srvyr::survey_median(duration, na.rm=TRUE),
wtd.mean = srvyr::survey_mean(duration, na.rm=TRUE),
median = srvyr::unweighted(median(duration, na.rm=TRUE)),
mean = srvyr::unweighted(mean(duration, na.rm=TRUE)))
Based on other questions/answers, I've also tried using dplyr::summarize(n = dplyr::n(),
but that results in the same error. Is the problem that it is not possible to use dplyr n() on a srvyr object? There does not appear to be a similar function in srvyr that can be used in a summarize call.
thanks!