There are a few corners where matrices are treated differently from vectors and data.frames. I will demonstrate the examples I have on a few simple objects:
1. Selection of non existent elements should return NA:
x[20]
<NA>
NA
df[20,]
A B C D E
NA NA NA NA NA <NA>
X[20,]
Error in X[20, ] : subscript out of bounds
2. having "NA" in selection should be allowed:
x[c("a", NA, "c")]
a <NA> c
1 NA 3
df[c("a", NA, "c"),]
A B C D E
a 5.1 3.5 1.4 0.2 setosa
NA NA NA NA NA <NA>
c 4.7 3.2 1.3 0.2 setosa
X[c("a", NA, "c"),]
Error in X[c("a", NA, "c"), ] : subscript out of bounds
3. row and column names should not have names themselves
names(x) <- setNames(letters[1:5], LETTERS[1:5])
names(x)
[1] "a" "b" "c" "d" "e"
rownames(df) <- setNames(letters[1:10], LETTERS[1:10])
rownames(df)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
rownames(X) <- setNames(letters[1:10], LETTERS[1:10])
rownames(X)
A B C D E F G H I J
"a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
There are a few corners where matrices are treated differently from vectors and data.frames. I will demonstrate the examples I have on a few simple objects:
1. Selection of non existent elements should return NA:
2. having "NA" in selection should be allowed:
3. row and column names should not have names themselves