dplyr mutate case_when 产生 NA

问题描述

我在 case_when() 中使用 mutate() 并获得预期输出,但我也收到有关生成 NA 的警告。不过,我想不通为什么。据我所知,无论如何,RHS 都应该属于同一类型。我已将所有 RHS 条件包装在 as.double() 调用中,以确保它们属于同一类型,但这并没有什么区别。警告暗示我的默认条件是创建 NA。

依赖

我正在使用 library(mc2d) 来获取下面使用的 rpert() 函数。

源数据

> simulationTable %>% select(count,Productivity_Low__c,Productivity_ML__c,Productivity_High__c)
# A tibble: 20 x 4
# Rowwise: 
   count Productivity_Low__c Productivity_ML__c Productivity_High__c
   <int>               <dbl>              <dbl>                <dbl>
 1     2                   0                  0                    0
 2     2                   0                  0                    0
 3     0                   0                  0                    0
 4     2                   0                  0                    0
 5     6                   0                  0                    0
 6     1                   0                  0                    0
 7     0                   0                  0                    0
 8     0                   0                  0                    0
 9     0                   0                  0                    0
10     0                   0                  0                    0
11     0                   0                  0                    0
12     0                   0                  0                    0
13     0                   0                  0                    0
14     0                   0                  0                    0
15     1                   0                  0                    0
16     0               10000              75000               500000
17     0               10000              75000               500000
18     1               10000              75000               500000
19     0               10000              75000               500000
20     0               10000              75000               500000

我的代码

simulationTable <- simulationTable %>%
  mutate(
    productivity = case_when(count>0 & Productivity_High__c>0 ~ as.double(sum(rpert(count,Productivity_High__c))),TRUE ~ as.double(0))
  )

警告

Problem with `mutate()` input `productivity`.
ℹ NAs produced
ℹ Input `productivity` is `case_when(...)`.
ℹ The error occurred in row 1.NAs producedProblem with `mutate()` input `productivity`.
ℹ NAs produced
ℹ Input `productivity` is `case_when(...)`.
ℹ The error occurred in row 2.NAs producedProblem with `mutate()` input `productivity`.
ℹ NAs produced
ℹ Input `productivity` is `case_when(...)`.
ℹ The error occurred in row 4.NAs producedProblem with `mutate()` input `productivity`.
ℹ NAs produced
ℹ Input `productivity` is `case_when(...)`.
ℹ The error occurred in row 5.NAs producedProblem with `mutate()` input `productivity`.
ℹ NAs produced
ℹ Input `productivity` is `case_when(...)`.
ℹ The error occurred in row 6.NAs producedProblem with `mutate()` input `productivity`.
ℹ NAs produced
ℹ Input `productivity` is `case_when(...)`.
ℹ The error occurred in row 15.NAs produced

解决方法

?奇数

和其他人一样,我无法重现这些错误。但是(我不知道这个功能)我没有得到 869414.4 作为答案

temp_id

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...