gpt4 book ai didi

R:创建(长)假人列表时的警告

转载 作者:行者123 更新时间:2023-12-04 20:01:00 30 4
gpt4 key购买 nike

列的虚拟列 c和一个给定的值 x等于 1如果 c==x和 0 其他。通常,通过为列创建虚拟对象 c , 一排除一个值 x选择,因为最后一个虚拟列不添加任何信息 w.r.t.已经存在的虚拟列。

这是我如何尝试为列创建一长串假人列表 firm , 在 data.table :

values <- unique(myDataTable$firm)
cols <- paste('d',as.character(inds[-1]), sep='_') # gives us nice d_value names for columns
# the [-1]: I arbitrarily do not create a dummy for the first unique value
myDataTable[, (cols):=lapply(values[-1],function(x)firm==x)]

此代码可靠地适用于具有较小唯一值的先前列。 firm然而更大:
tr(values)
num [1:3082] 51560090 51570615 51603870 51604677 51606085 ...

尝试添加列时收到警告:
Warning message:
truelength (6198) is greater than 1000 items over-allocated (length = 36). See ?truelength. If you didn't set the datatable.alloccol option very large, please report this to datatable-help including the result of sessionInfo().

据我所知,仍然有我需要的所有列。我可以忽略这个问题吗?它会减慢 future 的计算速度吗?我不知道如何理解这个和 truelength 的相关性。 .

最佳答案

以阿伦的评论作为答案。
您应该使用 alloc.col函数将 data.table 中所需的列数预先分配给大于预期 ncol 的数字。

alloc.col(myDataTable, 3200)

此外,根据您使用数据的方式,我建议考虑将宽表改造成长表,请参阅 EAV .那么每种数据类型只需要一列。

关于R:创建(长)假人列表时的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29615181/

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