On 15/10/2021 4:31 p.m., petr smirnov wrote:
Hi,

Is base::intersect guaranteed to return items in the order they (first)
appear in the first argument? I couldn't find any mention of this in the
help file for set operations.

No, that's just what the current implementation does.

It's conceivable that swapping x and y could let it be faster in some circumstances. Or maybe there's a completely different implementation that's better for some data types. In either of those cases the order could change.

Generally speaking, the functions that treat vectors as sets make no assumptions and no guarantees about order, because sets are unordered.

If you need the current behaviour to be guaranteed, probably the easiest way is to copy the function: it's very simple.

Duncan Murdoch


If so, could this be documented on the help page?

Thanks,
Petr

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to