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

`as_factor.labelled` should preserve the variable label #177

Closed
anhqle opened this Issue Jun 7, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@anhqle
Copy link

anhqle commented Jun 7, 2016

When convert a labelled vector to a factor using as_factor, the variable name, stored in the attribute label, should be preserved. I'd be happy to contribute a pull request if you deem this a good idea.

Example:

# Create a labelled vector with both (variable) label and (value) labels
my_var <- sample(c(0, 1), 10, replace = TRUE)
class(my_var) <- "labelled"
attr(my_var, "label") <- "My Variable"
attr(my_var, "labels") <- c("Agree" = 1, "Disagree" = 0)


my_var # Has both variable label and value labels
as_factor(my_var) # No longer has the variable label

larmarange added a commit to larmarange/labelled that referenced this issue Jun 7, 2016

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jun 7, 2016

Yes, I'd be happy to review a pull request

hadley added a commit that referenced this issue Jun 8, 2016

Replace tagged NAs in as_factor.
Now preserves all labels in factor levels (labels not in data are added to the end), so is part of #177

@itsdalmo itsdalmo referenced this issue Jun 9, 2016

Closed

WIP: Basic API for tagged missing values #175

3 of 5 tasks complete

hadley added a commit that referenced this issue Jun 9, 2016

Fix for #172 (labels) and #177 (variable label). (#179)
* Add test for #172. Labels for missing values should be preserved.

* Importing setNames from stats

* Rebased fix for #172 and #177.
as_factor now preserves variable label. (#177)

as_factor includes and sorts both existing and missing labels. (#172)

* Use stats::setNames instead of importing.

* Added bullets explaining fixes for #172 and #177 to news.
@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jun 9, 2016

Fixed by #179

@hadley hadley closed this Jun 9, 2016

@lock lock bot locked and limited conversation to collaborators Jun 27, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.