为什么Dataa.table通过引用更新名称(DT),即使我将其赋值给另一个变量?
data.table
vector
:
library(data.table)set.seed(42)DT <- data.table(x = runif(100), y = runif(100))names1 <- names(DT)
str(names1)# chr [1:2] "x" "y"class(names1)# [1] "character"dput(names1)# c("x", "y")
data.table
DT[ , z := runif(100)]names1# [1] "x" "y" "z"
:=
<-
data.table
c()
:
library(data.table)set.seed(42)DT <- data.table(x = runif(100), y = runif(100))names1 <- names(DT)names2 <- c(names(DT)) all.equal(names1, names2)# [1] TRUEDT[ , z := runif(100)]names1# [1] "x" "y" "z"names2# [1] "x" "y"
names1 <- names(DT)
data.table
<-
data.table
data.frame
names1 <- names(DT)
names2 <- c(names(DT))
?
蝴蝶刀刀
江户川乱折腾