Hi,
I know how to use across if I want to summarise some variables.
The issue is I don't know how to summarise a function over a third one.
For example
Here I try, using the dataset from the survey package named "api", to obtain the sum of the variable fpc grouping by cname across the dummies s1 to s3
library(survey)
data(api)
apistrat %>%
mutate(s1=if_else(comp.imp=="Yes",1,0),
s2=if_else(stype=="E",1,0),
s31=if_else(dnum>=500,1,0)) %>%
group_by(cname) %>%
summarise(across(s1:s3,~sum(fpc)))
Here I could do It, but using a filter and repeating the code three times
apistrat %>%
mutate(s1=if_else(comp.imp=="Yes",1,0)) %>%
filter(s1==1) %>%
group_by(cname) %>%
summarise(population=sum(fpc))
apistrat %>%
mutate(s2=if_else(stype=="E",1,0)) %>%
filter(s2==1) %>%
group_by(cname) %>%
summarise(population=sum(fpc))
apistrat %>%
mutate(s3=if_else(dnum>=400,1,0)) %>%
filter(s3==1) %>%
group_by(cname) %>%
summarise(population=sum(fpc))
As always, thanks for your time and interest