gpt4 book ai didi

r - R 中的 data.table 不能使用 dput

转载 作者:行者123 更新时间:2023-12-03 21:39:55 26 4
gpt4 key购买 nike

我有以下 data.table,我不能使用 dput 命令的输出来重新创建它:

> ddt
Unit Anything index new
1: A 3.4 1 1
2: A 6.9 2 1
3: A1 1.1 1 2
4: A1 2.2 2 2
5: B 2.0 1 3
6: B 3.0 2 3
>
>
> str(ddt)
Classes ‘data.table’ and 'data.frame': 6 obs. of 4 variables:
$ Unit : Factor w/ 3 levels "A","A1","B": 1 1 2 2 3 3
$ Anything: num 3.4 6.9 1.1 2.2 2 3
$ index : num 1 2 1 2 1 2
$ new : int 1 1 2 2 3 3
- attr(*, ".internal.selfref")=<externalptr>
- attr(*, "sorted")= chr "Unit" "Anything"
>
>
> dput(ddt)
structure(list(Unit = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("A",
"A1", "B"), class = "factor"), Anything = c(3.4, 6.9, 1.1, 2.2,
2, 3), index = c(1, 2, 1, 2, 1, 2), new = c(1L, 1L, 2L, 2L, 3L,
3L)), .Names = c("Unit", "Anything", "index", "new"), row.names = c(NA,
-6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x8948f68>, sorted = c("Unit",
"Anything"))
>

粘贴时出现以下错误:
> dt = structure(list(Unit = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("A", 
+ "A1", "B"), class = "factor"), Anything = c(3.4, 6.9, 1.1, 2.2,
+ 2, 3), index = c(1, 2, 1, 2, 1, 2), new = c(1L, 1L, 2L, 2L, 3L,
+ 3L)), .Names = c("Unit", "Anything", "index", "new"), row.names = c(NA,
+ -6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x8948f68>, sorted = c("Unit",
Error: unexpected '<' in:
"3L)), .Names = c("Unit", "Anything", "index", "new"), row.names = c(NA,
-6L), class = c("data.table", "data.frame"), .internal.selfref = <"
> "Anything"))
Error: unexpected ')' in ""Anything")"

问题出在哪里,如何解决?谢谢你的帮助。

最佳答案

问题是dput打印出外部指针地址(这是 data.table 在内部使用的东西,并在需要时重建),你不能真正使用它。

如果你手动剪掉了 .internal.selfref部分,它会正常工作,除了来自 data.table 的一次性投诉对于某些操作。

您可以将 FR 添加到 data.table关于这一点,但它需要修改 data.table 中的基函数, 类似于 rbind目前正在处理。

关于r - R 中的 data.table 不能使用 dput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25533332/

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