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

Retain factor levels (even if unseen) #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jonocarroll
Copy link
Contributor

@jonocarroll jonocarroll commented Jul 23, 2018

Closes #39.

Added as a branch of the dt_paste PR because I wasn't sure how it would interact (diff will reduce significantly once that PR is merged).

Extracts (all) factor levels and pastes them into the factor (not as.factor) call.

head(iris) %>% df_paste()
data.frame(
   Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, 5.4),
    Sepal.Width = c(3.5, 3, 3.2, 3.1, 3.6, 3.9),
   Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4, 1.7),
    Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2, 0.4),
        Species = factor(c("setosa", "setosa", "setosa", "setosa", "setosa",
                           "setosa"), levels = c("setosa", "versicolor",
                           "virginica"))
)

Please test thoroughly before merging.

@jonocarroll
Copy link
Contributor Author

Should the levels part start on a new line? Indenting that properly may be fiddly.

@jonocarroll
Copy link
Contributor Author

This PR may now be out of date. I will confirm, but I think factor levels are now handled, no?

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

Successfully merging this pull request may close these issues.

df_paste preserves factors but drops unseen levels
1 participant