I wonder why two data frames a
and b
have different outcomes when a non-existent rowname is retrieved. For example,
a <- as.data.frame(matrix(1:3, ncol = 1, nrow = 3, dimnames = list(c("A1", "A10", "B"), "V1")))
a
V1
A1 1
A10 2
B 3
b <- as.data.frame(matrix(4:5, ncol = 1, nrow = 2, dimnames = list(c("A10", "B"), "V1")))
b
V1
A10 4
B 5
Let's try to get "A10", "A1", "A" from data frame a
:
> a["A10", 1]
[1] 2
> a["A1", 1]
[1] 1 # expected
> a["A", 1]
[1] NA # expected
> a["B", 1]
[1] 3 # expected
> a["C", 1]
[1] NA # expected
Let's do the same for data frame b
:
> b["A10", 1]
[1] 4
> b["A1", 1]
[1] 4 # unexpected, should be NA
> b["A", 1]
[1] 4 # unexpected, should be NA
> b["B", 1]
[1] 5 # expected
> b["C", 1]
[1] NA # expected
Now that a["A", 1]
returns NA
, why does b["A", 1]
or b["A1", 1]
not?
PS. R version 3.5.2