写data.table语法作为其dplyr等价于修复9218868437227407266的整数64

时间:2017-04-02 03:19:45

标签: r data.table dplyr

我遇到了NA问题而不是9218868437227407266它显示bit64,如下所述:fread() fails with missing values in integer64 columns

我已加载data.table 1.9.5NAs或更高版本的软件包据称显示9218868437227407266s代替bit64,但它不起作用。此问题在此处描述,并且是dt[as.character(my_col) == "9218868437227407266", my_col := as.integer64(NA)] 问题:https://github.com/Rdatatable/data.table/issues/488

我把它写成"解决方案":

%>%

它有效,但我想知道如何在dplyr语法中编写它以使用db.events.aggregate( {$project: {startTime: 1, endTime: 1,matches: {$cond: [{$and:[ {$lt: ['$startTime',new Date()]}, {$gt: ['$endTime', {$add: [new Date(), '$duration']}]} ]},1,0]}}}, {$match: {matches:1}} ) 而不会发生意外崩溃。

非常感谢提前!

1 个答案:

答案 0 :(得分:1)

我们可以使用replace

library(dplyr)
dt %>%
   mutate(my_col = replace(my_col, as.character(my_col) == "9218868437227407266",
                         as.integer64(NA))