tab() for vectors
rdisalv2 opened this issue · comments
Hi,
I'm used to doing statar::tab(myvector)
to tabulate vectors (same for sum_up
). It seems that in the latest version of statar that tab only works on data.frame
s now.
I'm sure there are reasons for this choice, but is there any chance we could have statar::tab
branch for vectors? Right now I'm masking tab with some code (below), but an official implementation would be better.
# wrapper for statar::tab, to handle vector input
tab <- function(x, ...) {
xname_enquo <- enquo(x)
xname <- deparse(substitute(x))
if(is.vector(x)) {
x <- data.frame(x)
names(x) <- xname
statar::tab(x,!!xname_enquo,...)
} else if(is.data.frame(x)) {
statar::tab(x,...)
}
}
myvect <- c(1,2,3,3,3)
myvect %>% tab # works like it did in older version
tab(myvect) # same
tab(data.frame(x=c(1,2,3)),x) # still works
myvect %>% statar::tab(.) # throws error
Thanks!