在data.table :: dcast()期间,integer64未分配NA值,但默认为9218868437227407266

时间:2018-06-11 17:40:19

标签: r data.table

我有一个名为test的data.table,其中包括' freq' column的类为integer64,如下所示

>test
    event_type eventdt_qtr  freq
 1:         IF      200601    23
 2:       BDSF      200601    47
 3:       EDPM      200601   258
 4:       CPBP      200601    17
 5:         EF      200601  5132
 6:       EPWS      200601    96
 7:         EF      200602 15929
 8:         IF      200602    24
 9:       BDSF      200602    41
10:       CPBP      200602    16
11:       EDPM      200602   231
12:       EPWS      200602   109
13:       CPBP      200603    15
14:         IF      200603    42
15:       EDPM      200603   358
16:       BDSF      200603    72
17:       EPWS      200603    93
18:        DPA      200603     2
19:         EF      200603 48185
20:       BDSF      200604    47

>str(chk_1_1_means)
Classes ‘data.table’ and 'data.frame':  297 obs. of  3 variables:
 $ event_type : chr  "IF" "BDSF" "EDPM" "CPBP" ...
 $ eventdt_qtr: num  200601 200601 200601 200601 200601 ...
 $ freq       :integer64 23 47 258 17 5132 96 15929 24 ... 

当我在测试时执行data.table :: dcast()操作,而不是为现有的event_type和eventdt_qtr组合获取NA或0,我得到值9218868437227407266。我相信这个问题可能与{{3}有关},但我不知道如何解决它。

> test_tx <- data.table::dcast(test,eventdt_qtr ~ event_type,value.var = "freq")
> test_tx
   eventdt_qtr BDSF                CPBP                 DPA                EDPM                  EF
1:      200601   47                  17 9218868437227407266                 258                5132
2:      200602   41                  16 9218868437227407266                 231               15929
3:      200603   72                  15                   2                 358               48185
4:      200604   47 9218868437227407266 9218868437227407266 9218868437227407266 9218868437227407266
                  EPWS                  IF
1:                  96                  23
2:                 109                  24
3:                  93                  42
4: 9218868437227407266 9218868437227407266

注意:如果我明确转换了列&#39; freq&#39;我知道有一个修复程序(请参阅下面的解决方案)。到整数而不是整数64,但我不想进行任何类型的转换,因为我正在从Redshift读取数据并且必须保留data.table&#39; test&#39;代码中的下游。

> test$freq <- as.integer(test$freq)
> test_tx <- data.table::dcast(test,eventdt_qtr ~ event_type,value.var = "freq")
> test_tx
   eventdt_qtr BDSF CPBP DPA EDPM    EF EPWS IF
1:      200601   47   17  NA  258  5132   96 23
2:      200602   41   16  NA  231 15929  109 24
3:      200603   72   15   2  358 48185   93 42
4:      200604   47   NA  NA   NA    NA   NA NA

0 个答案:

没有答案