I'm trying to create a wrapper for xtabs with a custom function.
I tried doing this:
xtabs_fun <- function(data, variable) {
xtabs(~ variable, data = data)
}
But using it doesn't return the correct value.
xtabs_fun(mtcars, "cyl")
cyl
1
The expected output should be this:
xtabs(~ cyl, data = mtcars)
cyl
4 6 8
11 7 14