Hello,
I recently notice that I can use select(ends_with("")) over the code below:
library(survey)
data(api)
dstrata <- apistrat %>%
as_survey_design(strata = stype, weights = pw, fpc=fpc)
dstrata %>%
mutate(s1=if_else(comp.imp=="Yes",fpc,0),
s2=if_else(stype=="E",fpc,0),
s3=if_else(dnum>=500,fpc,0)) %>%
group_by(cname) %>%
summarise(
across(s1:s3, survey_total,vartype=c("cv"))
) %>%
select(ends_with("cv"))
But if I use a prefix when I compute the CVs, I lost the ability to use select(....
dstrata %>%
mutate(s1=if_else(comp.imp=="Yes",fpc,0),
s2=if_else(stype=="E",fpc,0),
s3=if_else(dnum>=500,fpc,0)) %>%
group_by(cname) %>%
summarise(
number_f=across(s1:s3, survey_total,vartype=c("cv"))
) %>%
select(ends_with("cv"))
# A tibble: 40 x 0
How can I adapt the later code in order to use select, and all the options, in order to rearrange the output estimation?
By the way, If I run glimpse using the last code, I receive:
Rows: 40
Columns: 4
$ cname <chr> "Alameda", "Amador", "Butte", "Colusa", "Contra Costa", "El Dorado", "Fresno", "Humboldt", "Inyo", "Ker~
$ number_fs1 <df[,2]> <data.frame[40 x 2]>
$ number_fs2 <df[,2]> <data.frame[40 x 2]>
$ number_fs3 <df[,2]> <data.frame[40 x 2]>
I know It's a bit silly, but I get confused.
Thanks for your time and interest.
Have a nice day