Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tab() for vectors #28

Open
rdisalv2 opened this issue Jul 23, 2017 · 0 comments
Open

tab() for vectors #28

rdisalv2 opened this issue Jul 23, 2017 · 0 comments

Comments

@rdisalv2
Copy link

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.frames 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant