-
Notifications
You must be signed in to change notification settings - Fork 115
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
WIP: Basic API for tagged missing values #175
Conversation
if (TYPEOF(x) != STRSXP) | ||
Rf_errorcall(R_NilValue, "`x` must be a character vector"); | ||
|
||
int n = Rf_length(x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to support long vectors here?
And add some more examples
NB: All plumbed up, but doesn't currently do anything
* update readstat api * add tests for reading from stata
And use in the labelled class.
Now preserves all labels in factor levels (labels not in data are added to the end), so is part of #177
Your last commit referenced the wrong issue I think. #177 is regarding variable label, did you mean #172? Would you consider moving the sort to the end, so missing labels are sorted in relation to the existing? E.g. changing to something like: # Replace each value with its label
vals <- unique(x)
levs <- replace_with(vals, unname(labels), names(labels))
# Ensure all labels are preserved
levs <- sort(c(setNames(vals, levs), labels))
levs <- unique(names(levs)) Would make it so: s1 <- labelled(c(1, 4), c("Agree" = 1, "Neutral" = 2, "Disagree" = 3, "Don't know" = 5))
as_factor(s1)
# Returns:
#> Levels: Agree Neutral Disagree 4 Don't know
# Instead of:
#> Levels: Agree 4 Neutral Disagree Don't know |
Closing because it's now so massive that it's impossible to review. |
Fixes #170
To do:
as_factor()
can re-label tagged missingsas_factor()
)