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

Different results using pipes #262

Closed
Beedmoser opened this issue Dec 20, 2022 · 2 comments
Closed

Different results using pipes #262

Beedmoser opened this issue Dec 20, 2022 · 2 comments

Comments

@Beedmoser
Copy link

Beedmoser commented Dec 20, 2022

Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on https://stackoverflow.com/ or https://community.rstudio.com/.

Please include a minimal reproducible example (AKA a reprex). If you've never heard of a reprex before, start by reading https://www.tidyverse.org/help/#reprex.

Brief description of the problem

library(DescTools)
library(tidyverse)

CramerV(table(d.pizza$driver, d.pizza$wine_delivered))
#> [1] 0.1328222

The correct result.

d.pizza %>% 
  select(driver, wine_delivered) %>% 
  table() %>% 
  as_tibble() %>% 
  mutate(t = DescTools::CramerV(driver, wine_delivered))
# A tibble: 14 × 4
   driver    wine_delivered     n     t
   <chr>     <chr>          <int> <dbl>
 1 Butcher   0                 85     0
 2 Carpenter 0                214     0
 3 Carter    0                212     0

All zeros in t using DescTools::CramerV.

d.pizza %>% 
  select(driver, wine_delivered) %>% 
  table() %>% 
  as_tibble() %>% 
  mutate(t = paste(driver, wine_delivered))

# A tibble: 14 × 4
   driver    wine_delivered     n t          
   <chr>     <chr>          <int> <chr>      
 1 Butcher   0                 85 Butcher 0  
 2 Carpenter 0                214 Carpenter 0
 3 Carter    0                212 Carter 0   
 4 Farmer    0                100 Farmer 0   

But it works here (using paste).

Probably related issue in reprex, which delivers

``` r
d.pizza %>% 
  select(driver, wine_delivered) %>% 
  table() %>% 
  as_tibble() %>% 
  mutate(t = DescTools::CramerV(driver, wine_delivered))
#> Error in d.pizza %>% select(driver, wine_delivered) %>% table() %>% as_tibble() %>% : konnte Funktion "%>%" nicht finden

Created on 2022-12-20 with reprex v2.0.2

@lionel-
Copy link
Member

lionel- commented Dec 21, 2022

That's because the data structures you've created are different:

table(d.pizza$driver, d.pizza$wine_delivered)
#>               0   1
#>   Butcher    85   9
#>   Carpenter 214  56
#>   Carter    212  19
#>   Farmer    100  17
#>   Hunter    139  15
#>   Miller    109  16
#>   Taylor    172  29

d.pizza %>%
  select(driver, wine_delivered) %>%
  table() %>%
  as_tibble()
#> # A tibble: 14 × 3
#>    driver    wine_delivered     n
#>    <chr>     <chr>          <int>
#>  1 Butcher   0                 85
#>  2 Carpenter 0                214
#>  3 Carter    0                212
#>  4 Farmer    0                100
#>  5 Hunter    0                139
#>  6 Miller    0                109
#>  7 Taylor    0                172
#>  8 Butcher   1                  9
#>  9 Carpenter 1                 56
#> 10 Carter    1                 19
#> 11 Farmer    1                 17
#> 12 Hunter    1                 15
#> 13 Miller    1                 16
#> 14 Taylor    1                 29

@lionel- lionel- closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
@Beedmoser
Copy link
Author

Beedmoser commented Dec 21, 2022 via email

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