Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weights argument fails when using dplyr group_by #146

Open
martinamorris opened this issue Mar 9, 2021 · 0 comments
Open

weights argument fails when using dplyr group_by #146

martinamorris opened this issue Mar 9, 2021 · 0 comments

Comments

@martinamorris
Copy link

martinamorris commented Mar 9, 2021

Example:

df <- data.frame(grp = rbinom(100, 1, .5),
                 var = rnorm(100, 10, 2),
                 wt = abs(rnorm(100)))

df %>% sjmisc::descr(weights = wt) # works

## Basic descriptive statistics

# var    type label  n NA.prc mean   sd   se             range      iqr skew
# grp integer   grp 85      0 0.51 0.50 0.05           1 (0-1) 1.000000 0.08
# var numeric   var 85      0 9.85 1.85 0.18 8.12 (6.41-14.53) 2.550164 0.19

df %>% group_by(grp) %>%           # doesn't work
  sjmisc::descr(weights = wt)

# Error in `[.data.frame`(descr_helper(tmp, max.length), , show) : 
#  undefined columns selected
> sessioninfo::package_info(pkgs = c("sjmisc", "dplyr"))
 package    * version date       lib source        
 assertthat   0.2.1   2019-03-21 [1] CRAN (R 4.0.0)
 cli          2.3.1   2021-02-23 [1] CRAN (R 4.0.4)
 crayon       1.4.1   2021-02-08 [1] CRAN (R 4.0.3)
 digest       0.6.27  2020-10-24 [1] CRAN (R 4.0.3)
 dplyr      * 1.0.4   2021-02-02 [1] CRAN (R 4.0.4)
 ellipsis     0.3.1   2020-05-15 [1] CRAN (R 4.0.0)
 fansi        0.4.2   2021-01-15 [1] CRAN (R 4.0.3)
 generics     0.1.0   2020-10-31 [1] CRAN (R 4.0.3)
 glue         1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
 insight      0.13.1  2021-02-22 [1] CRAN (R 4.0.4)
 lifecycle    1.0.0   2021-02-15 [1] CRAN (R 4.0.4)
 magrittr     2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
 pillar       1.5.1   2021-03-05 [1] CRAN (R 4.0.3)
 pkgconfig    2.0.3   2019-09-22 [1] CRAN (R 4.0.0)
 purrr        0.3.4   2020-04-17 [1] CRAN (R 4.0.0)
 R6           2.5.0   2020-10-28 [1] CRAN (R 4.0.3)
 rlang        0.4.10  2020-12-30 [1] CRAN (R 4.0.3)
 sjlabelled   1.1.7   2020-09-24 [1] CRAN (R 4.0.3)
 sjmisc       2.8.6   2021-01-07 [1] CRAN (R 4.0.3)
 tibble       3.1.0   2021-02-25 [1] CRAN (R 4.0.4)
 tidyselect   1.1.0   2020-05-11 [1] CRAN (R 4.0.0)
 utf8         1.1.4   2018-05-24 [1] CRAN (R 4.0.0)
 vctrs        0.3.6   2020-12-17 [1] CRAN (R 4.0.3)

Not sure you intended for these tools to work with group_by -- but it would be great if they did :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant