[Rd] partial matching of row names in [-indexing

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Sat Jan 15 02:39:59 CET 2022


   People are often surprised that row-indexing a data frame by [ + 
character does partial matching (and annoyed that there is no way to 
turn it off:

https://stackoverflow.com/questions/18033501/warning-when-partial-matching-rownames

https://stackoverflow.com/questions/34233235/r-returning-partial-matching-of-row-names

https://stackoverflow.com/questions/70716905/why-does-r-have-inconsistent-behaviors-when-a-non-existent-rowname-is-retrieved


?"[" says:

Character indices can in some circumstances be partially matched
      (see ‘pmatch’) to the names or dimnames of the object being
      subsetted (but never for subassignment).  UNLIKE S (Becker et al_
      p. 358), R NEVER USES PARTIAL MATCHING WHEN EXTRACTING BY ‘[’, and
      partial matching is not by default used by ‘[[’ (see argument
      ‘exact’).

(EMPHASIS ADDED).

Looking through the rest of that page, I don't see any other text that 
modifies or supersedes that statement.

   Is this a documentation bug?

The example given in one of the links above:

b <- as.data.frame(matrix(4:5, ncol = 1, nrow = 2, dimnames = 
list(c("A10", "B"), "V1")))

b["A1",]  ## 4 (partial matching)
b[rownames(b) == "A1",]  ## logical(0)
b["A1", , exact=TRUE]    ## unused argument error
b$V1[["A1"]] ## subscript out of bounds error
b$V1["A1"]   ## NA



More information about the R-devel mailing list