Let the following table:
x <- sample(1:2, 100, replace = T)
tabela <- table(x)
To which I add margins
> addmargins(tabela)
x
1 2 Sum
51 49 100
However, I would like to change the "Sum" label to "Total". How do I do this?
My current workaround is to run addmargins
to get the function's source code, copy it to my script and change the string "Sum"
to "Total"
, but I imagine there is a cleverer way to accomplish this.
A quick look at addmargin
's source code will show that, when it's explicitly passed a function via it's FUN=
argument, it names the marginal column by deparsing the supplied function's name.
A quick solution, then, is to pass in a function that sums the elements but has the name that you'd like to have printed there.
Total <- sum
addmargins(tabela, FUN = Total)
# x
# 1 2 Total
# 49 51 100
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