I would like to round the results of the prop.table to one decimal place but it does not seem it work as intended. Any leads?
with(mtcars, table(vs, am)) |> prop.table(margin = 1) * 100 |> round()
>Solution :
Its all about the paranthesis:
with(mtcars, table(vs, am) |> prop.table(margin = 1) * 100) |>round(1)
am
vs 0 1
0 66.7 33.3
1 50.0 50.0
Note that what you have does not round the results of prop.table but rather rounds 100. If you want you could do
(with(mtcars, table(vs, am)) |> prop.table(margin = 1) * 100)|>round(1)
am
vs 0 1
0 66.7 33.3
1 50.0 50.0