gpt4 book ai didi

从 data.table 中删除多列

转载 作者:行者123 更新时间:2023-12-03 05:24:24 25 4
gpt4 key购买 nike

从 data.table 中删除多列的正确方法是什么?我当前正在使用下面的代码,但是当我不小心重复其中一个列名称时,出现了意外的行为。我不确定这是否是一个错误,或者我是否不应该以这种方式删除列。

library(data.table)
DT <- data.table(x = letters, y = letters, z = letters)
DT[ ,c("x","y") := NULL]
names(DT)
[1] "z"

以上工作正常,但是

DT <- data.table(x = letters, y = letters, z = letters)
DT[ ,c("x","x") := NULL]
names(DT)
[1] "z"

最佳答案

这看起来是一个可靠的、可重现的错误。它已归档为 Bug #2791

重复该列似乎会尝试删除后续列。
如果没有剩余列,则 R 会崩溃。

<小时/>

更新:现已在 v1.8.11 中修复。来自 NEWS :

Assigning to the same column twice in the same query is now an error rather than a crash in some circumstances; e.g., DT[,c("B","B"):=NULL] (delete by reference the same column twice). Thanks to Ricardo (#2751) and matt_k (#2791) for reporting. Tests added.

关于从 data.table 中删除多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16638484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com