tidyverse / magrittr

Improve the readability of R code with the pipe
https://magrittr.tidyverse.org
Other
957 stars 157 forks source link

Different results using pipes #262

Closed Beedmoser closed 1 year ago

Beedmoser commented 1 year ago

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- commented 1 year ago

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
Beedmoser commented 1 year ago

Ouch! – Sorry for wasting your time.

Beat Moser

Bergstrasse 9 8322 Madetswil

Tel.: +41 79 257 96 00

Von: Lionel Henry @.> Gesendet: Mittwoch, 21. Dezember 2022 09:12 An: tidyverse/magrittr @.> Cc: Beat Moser @.>; Author @.> Betreff: Re: [tidyverse/magrittr] Different results using pipes (Issue #262)

Closed #262https://github.com/tidyverse/magrittr/issues/262 as not planned.

— Reply to this email directly, view it on GitHubhttps://github.com/tidyverse/magrittr/issues/262#event-8084708347, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A4323VKUT6MJFLIXX4OTNPTWOK3V7ANCNFSM6AAAAAATEIVQKA. You are receiving this because you authored the thread.Message ID: @.**@.>>