1
Aparently ifelse
completelly改變的數量和不保留輸入的數據類型ERROR:ifelse(d == 0,NA,d),其中d是integer64返回無義( 「數」 的形式)
例如:
library(bit64)
d <- c(1:10,NA,12,0) %>% as.integer64()
d %>% str
Class 'integer64' num [1:13] 4.94e-324 9.88e-324 1.48e-323 1.98e-323 2.47e-323 ...
ifelse(d==0,NA,d) %>% str
num [1:13] 4.94e-324 9.88e-324 1.48e-323 1.98e-323 2.47e-323 ...
ifelse(d==0,5,d) %>% str
num [1:13] 4.94e-324 9.88e-324 1.48e-323 1.98e-323 2.47e-323 ...
ifelse(d==5,50,d) %>% str
num [1:13] 4.94e-324 9.88e-324 1.48e-323 1.98e-323 5.00e+01 ...
上圖: - 數字輸出是無稽之談 - 格式的輸出是「民」
這是一個已知的問題嗎?
是否有另一個功能用來代替ifelse
?
EDIT1:帶有data.table操作
d <- data.table(a=c(1:10,NA,12,0) %>% as.integer64)
d[a==0,a:=NA]
d
a
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: NA
12: 12
13: 9218868437227407266
#obve: still incorrect, NA was interpreted as a nonsense integer64
#now this works:
d <- data.table(a=c(1:10,NA,12,0) %>% as.integer64)
d[a==0,a:=as.integer64(NA)]
d
a
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: NA
12: 12
13: NA
EDIT2替換ifelse
:tryed pading ifelse as.integer64的輸出()。不起作用!
d <- c(1:10,NA,12,0) %>% as.integer64()
ifelse(d==0,as.integer64(NA),as.integer64(d))
[1] 4.940656e-324 9.881313e-324 1.482197e-323 1.976263e-323 2.470328e-323 2.964394e-323 3.458460e-323 3.952525e-323
[9] 4.446591e-323 4.940656e-323 NA 5.928788e-323 0.000000e+00
編輯3:添加的源包(bit64)
哪個軟件包用於'integer64'(bit64?)? –
對ifelse的不足之處的總結總結在這裏,同時討論一個新的ifelse2版本:https://stat.ethz.ch/pipermail/r-devel/2016-August/072970.html –
@RYoda:是的,我正在使用bit64軟件包(剛更新了這個問題 – LucasMation