I would like to make use of the compound assignment pipe operator %<>%
. For example using the code below I can generate a simple data frame with the required proportions:
data("mtcars")
Vectorize(require)(package = c("magrittr", "gmodels"),
character.only = TRUE)
mtcars_sum <- CrossTable(mtcars$am, mtcars$cyl)$prop.row
as illustrated:
> head(mtcars_sum)
y
x 4 6 8
0 0.1578947 0.2105263 0.6315789
1 0.6153846 0.2307692 0.1538462
I would like to undertake the same transformation but using the %<>
pipe:
mtcars_sum %<>%
CrossTable(mtcars$am, mtcars$cyl)$prop.row
this returns the following error:
> mtcars_sum %<>%
+ CrossTable(mtcars$am, mtcars$cyl)$prop.row
Error in .$CrossTable(mtcars$am, mtcars$cyl) :
3 arguments passed to '$' which requires 2
What am I missing?