Aparently ifelse
completelly番号を変更し、入力ERROR:ifelse( "NUM" 形態で)、dはinteger64戻りナンセンスである(D == 0、NA、D)、
のデータ・タイプを保存しませんたとえば:
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 ...
上: - 出力内の数字はナンセンス ある - フォーマットの出力が「NUM」
あり、これは既知の問題ですか?
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
を交換する:しようと試みifelse as.integer64の出力をpading()。動作しません!
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