How to round all the values of a prop.table in R in one line?
You need to separate multiplication into a separate operation:
mtcars$cyl %>% table() %>% prop.table() %>% `*`(100) %>% round(2)
We can also use {}
to evaluate the (...
) as a whole within the %>% ... %>%
before switching to the next %>%
mtcars$cyl %>%
table() %>%
prop.table() %>% {. * 100} %>%
round(2)
.
# 4 6 8
# 34.38 21.88 43.75