Skip to content
Prev 60448 / 63421 Next

partial matching of row names in [-indexing

Although implicit, but what I don't think anyone has mentioned is that
the partial matching of row names only applies if the row name is
uniquely matched, as in:
a b
A1 1 a

If it matches two or more rows, you get:
a    b
NA NA <NA>

just as you would get if there is no match:
a    b
NA NA <NA>

So, the current behavior is dependent on what the other similar row
names too, that is, what might work at one point, might break when new
data are added to the data frame.

This is a behavior that I think stems from someone thought it's handy
while working interactively with data.frame:s interactively.  I think
it's an error-prone property when it comes to production code (script,
packages, and dynamic documents).  To me, this behavior should be
phased out from R to avoid silent errors and false scientific results.
It's not clear to me how to best deprecate the partial matching,
because of the default behavior of returning NA:s when there is no
match.  This means it can't be just a warning or an error.

My $.03

/Henrik
On Fri, Jan 14, 2022 at 6:55 PM Ben Bolker <bbolker at gmail.com> wrote: