Does dplyr have a preferred syntax for magrittr's %$% operator, since this is not loaded by default in the tidyverse? For example, I often use this:
data.frame(A=rbinom(100,1,p=0.5),B=rbinom(100,1,p=0.5)) %$% chisq.test(A,B)
Is there a preferred way to do this within the tidyverse alone? I feel like pull() should be able to do this, but I can't figure out how to call pull() twice inside the pipe.
From vigenettes of magrittr:
The “exposition” pipe operator,
%$%exposes the names within the left-hand side object to the right-hand side expression. Essentially, it is a short-hand for using the with functions.
So you could do it with with:
data.frame(A=rbinom(100,1,p=0.5),B=rbinom(100,1,p=0.5)) %>% with(chisq.test(A,B))
You can use a dot . to refer to the original dataframe, and use curly braces {} to prevent %>% filling in the first argument:
data.frame(A=rbinom(100,1,p=0.5),B=rbinom(100,1,p=0.5)) %>% 
    {chisq.test(.$A, .$B)} 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With