A traditional way of making a table in R:
data(mtcars)
round(100*prop.table(xtabs(~ gear + cyl, data = mtcars), 1), 2)
returns
cyl
gear 4 6 8
3 6.67 13.33 80.00
4 66.67 33.33 0.00
5 40.00 20.00 40.00
To replicate this using the magrittr
pipes, I've tried:
library(magrittr)
mtcars %>%
xtabs(~ gear + cyl, data = .) %>%
prop.table(., 1)
which works great up to this point
cyl
gear 4 6 8
3 0.06666667 0.13333333 0.80000000
4 0.66666667 0.33333333 0.00000000
5 0.40000000 0.20000000 0.40000000
but any attempt to perform the next part, wherein I convert proportions to percentages, and then round, results in an error. For instance:
mtcars %>%
xtabs(~ gear + cyl, data = .) %>%
100*prop.table(., 1)
and
mtcars %>%
xtabs(~ gear + cyl, data = .) %>%
prop.table(., 1) %>%
100 * .
all result in an error. What am I missing?