R Under development (unstable) (2024-03-19 r86153 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(survey) Loading required package: grid Loading required package: Matrix Loading required package: survival Attaching package: 'survey' The following object is masked from 'package:graphics': dotchart > > # don't throw an error on domains of size 1, just return NA > input <- mtcars > input$carb <- factor(input$carb) > design <- svydesign(ids = ~0, weights = NULL, data = input) > svyby( + ~mpg, + ~carb, + design, + svyvar + ) carb mpg se 1 1 36.01619 11.2823286 2 2 29.94444 9.0030898 3 3 1.11000 0.4604066 4 4 15.29656 4.3174617 6 6 NA NA 8 8 NA NA > > > ## same n with na.rm=TRUE as subset(, !is.na) > input$mpg[1]<-NA > design <- svydesign(ids = ~0, weights = NULL, data = input) > stopifnot(all.equal(svyvar(~mpg, design, na.rm=TRUE), + svyvar(~mpg, subset(design, !is.na(mpg))))) > > proc.time() user system elapsed 1.53 0.21 1.73