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

have tabyl() take multiple variables and compare them? #39

Closed
sfirke opened this issue Jul 14, 2016 · 3 comments
Closed

have tabyl() take multiple variables and compare them? #39

sfirke opened this issue Jul 14, 2016 · 3 comments

Comments

@sfirke
Copy link
Owner

sfirke commented Jul 14, 2016

This might be better off as a separate function. The idea would be that mtcars %>% tabyl(cyl, gear) returns the result of:

full_join(tabyl(mtcars$cyl), tabyl(mtcars$gear), by = c("mtcars_cyl" = "mtcars_gear")) %>%
  setNames(c("value", "cyl_n", "cyl_percent", "gear_n", "gear_percent"))

# A tibble: 5 x 5
  value cyl_n cyl_percent gear_n gear_percent
  <dbl> <int>       <dbl>  <int>        <dbl>
1     4    11     0.34375     12      0.37500
2     6     7     0.21875     NA           NA
3     8    14     0.43750     NA           NA
4     3    NA          NA     15      0.46875
5     5    NA          NA      5      0.15625

Would it return n? %? Both? Have that be user-specified? If just n, it could take advantage of the adorn_crosstab function I'm working on.

@sfirke
Copy link
Owner Author

sfirke commented Jul 14, 2016

@ffirke is this what you were talking about?

@ffirke
Copy link

ffirke commented Jul 14, 2016

No, but it's interesting.

I just meant tabyl taking two results and effectively grouping by both of them. So I can run transactions %>% tabyl(year, team) and get a dataframe with the number of results for each team/year combination (with optional percentages by group--there were 10 White Sox transactions in 2015, which is 1% of total transactions in the DF, 10% of the 2015 transactions, and 25% of the White Sox transactions).

All this behavior is basically just similar to SAS's proc freq.

@sfirke
Copy link
Owner Author

sfirke commented Jun 15, 2017

I think crosstab() - soon to be a 2-way tabyl() - does this.

@sfirke sfirke closed this as completed Jun 15, 2017
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

2 participants