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

replace NA values in tabyl() counts with 0? #48

Closed
sfirke opened this issue Jul 31, 2016 · 0 comments
Closed

replace NA values in tabyl() counts with 0? #48

sfirke opened this issue Jul 31, 2016 · 0 comments
Assignees

Comments

@sfirke
Copy link
Owner

sfirke commented Jul 31, 2016

Only affects calls where there's an unrepresented level in a factor variable, so this is a niche case.

Instead of:

> tabyl(sorted_with_na_and_fac$grp, sort = TRUE)
  sorted_with_na_and_fac$grp  n percent valid_percent
1                          c  2    0.50     0.6666667
2                          a  1    0.25     0.3333333
3                          b NA      NA            NA
4                       <NA>  1    0.25            NA

Return:

> tabyl(sorted_with_na_and_fac$grp, sort = TRUE)
  sorted_with_na_and_fac$grp n percent valid_percent
1                          c 2    0.50     0.6666667
2                          a 1    0.25     0.3333333
3                          b 0    0.00     0.0000000
4                       <NA> 1    0.25     0.0000000

Could likely be done with:

  # replace NA values with zeroes
  result[is.na(result)] <- 0

Though I think I'd want to retain the NA representation of row = NA and column = valid_percent, to show that missing values is not in fact 0% once they've been filtered out.

@sfirke sfirke self-assigned this Aug 6, 2016
@sfirke sfirke closed this as completed in 1d14dec Aug 18, 2016
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