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

get_comparisons() creates comparisons for unused groups #67

Closed
benediktclaus opened this issue Sep 10, 2020 · 2 comments
Closed

get_comparisons() creates comparisons for unused groups #67

benediktclaus opened this issue Sep 10, 2020 · 2 comments

Comments

@benediktclaus
Copy link

get_comparisons() is a really handy function, although it creates comparisons for all factor levels and not just the ones used in the data (see below). Is this behaviour intentional or can this be fixed?

library(tibble)
library(rstatix)
#> 
#> Attache Paket: 'rstatix'
#> The following object is masked from 'package:stats':
#> 
#>     filter

factor_data <- tibble(
  groups = factor(c("a", "b"), levels = c("a", "b", "c")) 
)

factor_data
#> # A tibble: 2 x 1
#>   groups
#>   <fct> 
#> 1 a     
#> 2 b

get_comparisons(factor_data, groups)
#> $V1
#> [1] "a" "b"
#> 
#> $V2
#> [1] "a" "c"
#> 
#> $V3
#> [1] "b" "c"

Created on 2020-09-10 by the reprex package (v0.3.0)

@benediktclaus benediktclaus changed the title get_comparisons() created comparisons for unused groups get_comparisons() creates comparisons for unused groups Sep 10, 2020
@kassambara
Copy link
Owner

Thank you for reporting this. We need to use the function droplevels() to automatically handle this issue inside the get_comparisons() function.

In the meantime, you can try the following R code:

library(tibble)
library(rstatix)
factor_data <- tibble(
  groups = factor(c("a", "b"), levels = c("a", "b", "c")) 
)
# droplevels() will drop unused  levels
get_comparisons(droplevels(factor_data), groups)

@kassambara
Copy link
Owner

fixed now, thanks

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

2 participants