我想在不加载 data.table 的情况下使用 data.table 中的 := 运算符。例如对于下面的data.table,我想添加另一列名为error
:
DT <- data.table::data.table(station = rep(1:1,52560), mod = rnorm(1*52560),obs = rnorm(1*52560))
但是,如果我执行以下操作,一切顺利,但我很困惑它是如何在不引用包 data.table 的情况下工作的(未加载 data.table 库)?!!
DT[ , `:=`(error = mod - obs)]
如何使用 data.table:::
:=
重写上面的行?!!
最佳答案
不确定我理解正确,但关于:
I am going to use this in another package and preferably I want not to load data.table. – newbie
I am importing the package, I have no other choice since data.table will not work if I do not import. Would importing alone take care of this? – newbie
是导入 data.table 而不是依赖于你的包。您可能已经尝试过,但由于这个常见问题而没有奏效。请参阅此处的解决方案:
Using data.table package inside my own package
关于r - 在未加载 data.table 包时使用 data.table 中的 `:=`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35352591/