-
Notifications
You must be signed in to change notification settings - Fork 4
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
Base R function for length(unique(x)) #149
Comments
I can see how it can help readability, but what's your thoughts how to increase the performance? My understanding is that one still has to allocate memory for and keep track of all unique values, which is what |
Faster performance should be for factors, which keep track of possible levels. One solution might be to make But in general yes, many times I also wished to have a function that does |
I think your only option would be to go to the c code. I think it would mean adding a fourth op at: and then returning early at This would avoid the additional allocation for unique and doesn't seem too invasive (that said, I've no idea how involved the first (op) part is/would be ...) |
Thanks both. Awesome. Sounds like there's indeed also room for performance improvements, by avoiding that memory allocation and copying at the end.
It sounds like Introducing |
It's common to need to know how many unique elements there are in a vector. This often happens on the REPL during exploration of data. A single function like
could save time and help readability.
The text was updated successfully, but these errors were encountered: