R中有数据表的怪异情况,列名混合 [英] Weird case with data tables in R, column names are mixed
问题描述
因此,我在名为 mc_with_devices
的数据表中创建了一个名为 mc_split_device
的变量.但是,如果我键入 mc_with_devices $ mc_split
,则会得到列 mc_split_device
的值,而我从未创建任何名称为 mc_split
的变量.>
请参见哈德利·威克姆(Hadley Wickham)的Advanced R :
$是一个简写运算符,其中x $ y等于x [["y",确切= FALSE]].通常用于访问数据帧中的变量,例如mtcars $ cyl或diamonds $ carat.
所以 exact = FALSE
是 $ mc_split
起作用的原因,尽管没有确切名称的列.
顺便说一句,我不相信 mc_with_devices [,..(mc_split)]
在没有双引号的情况下也可以使用.以下将起作用:
mc_with_devices [,"mc_split_resp"]
So I have created this variable that is called mc_split_device
inside the datatable called mc_with_devices
. However, If I type mc_with_devices$mc_split
I get the values of the column mc_split_device
while I never created any variable with the name mc_split
.
See Hadley Wickham's Advanced R:
$ is a shorthand operator, where x$y is equivalent to x[["y", exact = FALSE]]. It’s often used to access variables in a data frame, as in mtcars$cyl or diamonds$carat.
So the exact=FALSE
is the reason why $mc_split
works despite there not being a column with that exact name.
As an aside, I don't believe mc_with_devices[,.(mc_split)]
will work without doublequotes. The following will work:
mc_with_devices[,"mc_split_resp"]
这篇关于R中有数据表的怪异情况,列名混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!