Skip to content

Retain factor levels (even if unseen)#75

Open
jonocarroll wants to merge 3 commits into
MilesMcBain:masterfrom
jonocarroll:feature/retain_factor
Open

Retain factor levels (even if unseen)#75
jonocarroll wants to merge 3 commits into
MilesMcBain:masterfrom
jonocarroll:feature/retain_factor

Conversation

@jonocarroll

@jonocarroll jonocarroll commented Jul 23, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

@jonocarroll

Copy link
Copy Markdown
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