使用`$`的部分列名。错误或功能?

时间:2018-05-23 10:00:01

标签: r

我在错误输入列名称(省略最后一个字母)之后注意到data.frame仍然返回该列的值。例如:

dt <- data.frame(Column = LETTERS[1:10], Col = 1:10)

# Using the first 4 letters of the first column returns:
dt$Colu
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"

# Using the first 3 letters of first column/full column name of second 
# column returns:
dt$Col
 [1]  1  2  3  4  5  6  7  8  9 10

# using the first two letters of both columns (ambiguous) returns:
dt$Co
 NULL

我只是想知道这是否是预期的行为。

R3.5.0

0 个答案:

没有答案