gpt4 book ai didi

r - PowerPC 和 SPARC(均为大端)上的 data.table 不正确行为

转载 作者:行者123 更新时间:2023-12-02 01:49:22 24 4
gpt4 key购买 nike

有一个data.table dt,我在其中使用cut做了一些分类:

require(data.table)
set.seed(1)
dt <- data.table(x = rnorm(10))
dt[, y := cut(x, breaks = c(-Inf, 0, Inf), labels = 1:2)]

如果我将结果因子 y 转换为数值(使用基于 ?factor 的函数 as.Numeric),二分查找不再起作用,尽管 z 是数字。

as.Numeric <- function(f){
as.numeric(levels(f))[f]
}

dt[, z := as.Numeric(y)] # as.numeric(as.character(y))
# is working ...
dt
## x y z
## 1: -0.6264538 1 1
## 2: 0.1836433 2 2
## 3: -0.8356286 1 1
## 4: 1.5952808 2 2
## 5: 0.3295078 2 2
## 6: -0.8204684 1 1
## 7: 0.4874291 2 2
## 8: 0.7383247 2 2
## 9: 0.5757814 2 2
## 10: -0.3053884 1 1

setkey(dt, z)
dt
## x y z
## 1: 0.1836433 2 2
## 2: 1.5952808 2 2
## 3: 0.3295078 2 2
## 4: 0.4874291 2 2
## 5: 0.7383247 2 2
## 6: 0.5757814 2 2
## 7: -0.6264538 1 1
## 8: -0.8356286 1 1
## 9: -0.8204684 1 1
## 10: -0.3053884 1 1

dt[J(1)] # doesn't work
## x y z
## 1: NA NA 1

dt[y == 1, ] # works fine
## x y z
## 1: -0.6264538 1 1
## 2: -0.8356286 1 1
## 3: -0.8204684 1 1
## 4: -0.3053884 1 1

str(dt)
## Classes ‘data.table’ and 'data.frame': 10 obs. of 3 variables:
## $ x: num 0.184 1.595 0.33 0.487 0.738 ...
## $ y: Factor w/ 2 levels "1","2": 2 2 2 2 2 2 1 1 1 1
## $ z: num 2 2 2 2 2 2 1 1 1 1
## - attr(*, ".internal.selfref")=<externalptr>
## - attr(*, "sorted")= chr "z"

尝试再次设置 key ,没有帮助:

setkey(dt, z)
## Warning message:
## In setkeyv(x, cols, verbose = verbose) :
## Already keyed by this key but had invalid row order, key rebuilt. If you didn't go under the hood please let datatable-help know so the root cause can be fixed.

dt
## x y z
## 1: 0.1836433 2 2
## 2: 1.5952808 2 2
## 3: 0.3295078 2 2
## 4: 0.4874291 2 2
## 5: 0.7383247 2 2
## 6: 0.5757814 2 2
## 7: -0.6264538 1 1
## 8: -0.8356286 1 1
## 9: -0.8204684 1 1
## 10: -0.3053884 1 1

dt[J(1)] # doesn't work
## x y z
## 1: NA NA 1

矢量扫描 正在运行,因为不需要 key 。使用 as.numeric(as.character(y)) 也可以。也许 [-operator in as.Numeric 是个问题?使用与 dt 1.8.10 相同的代码,一切都像预期的那样。要找出代码在 1.9.3 中不再工作的原因并不是那么容易...

问题:

这是一个错误吗?

附:

sessionInfo()
## R version 3.1.0 (2014-04-10)
## Platform: powerpc64-unknown-linux-gnu (64-bit)

## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

## attached base packages:
## [1] splines grid stats graphics grDevices utils datasets
## [8] methods base

## other attached packages:
## [1] plyr_1.8.1 reshape2_1.4 lubridate_1.3.3 HP14int_0.1-15
## [5] Hmisc_3.14-4 Formula_1.1-1 survival_2.37-7 lattice_0.20-29
## [9] HP14unidata_1.1-1 data.table_1.9.3

## loaded via a namespace (and not attached):
## [1] cluster_1.15.2 digest_0.6.4 latticeExtra_0.6-26
## [4] memoise_0.2.1 RColorBrewer_1.0-5 Rcpp_0.11.1
## [7] stringr_0.6.2 tools_3.1.0

writeLines(paste("Endianess:", .Platform$endian))
## Endianess: big

最佳答案

现已修复 v1.9.5 on GitHub .感谢您的报告。

Compatibility with big endian machines (e.g., SPARC and PowerPC) is restored. Most Windows, Linux and Mac systems are little endian; type .Platform$endian to confirm. Thanks to Gerhard Nachtmann for reporting and the QEMU project for their PowerPC emulator.

关于r - PowerPC 和 SPARC(均为大端)上的 data.table 不正确行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23805911/

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