相关疑难解决方法(0)

为什么 all.equal 在 dplyr 的 mutate 函数中不起作用?

考虑以下代码:

library(dplyr)       
patientID <- c(1, 2, 3, 4)
age <- c(25, 34, 28, 52)
diabetes <- c("Type1", "Type2", "Type1", "Type1")
status <- c("Poor", "Improved", "Excellent", "Poor")
patientdata <- data.frame(patientID, age, diabetes, status)
myf <- function(patientID, age, diabetes, status) { isTRUE(all.equal(age, 34))}
mutate(patientdata, isAge34 = myf(patientID, age, diabetes, status))
Run Code Online (Sandbox Code Playgroud)

我写信myf返回TRUEwhere 行age == 34,但这不起作用:

  patientID age diabetes    status isAge34
1         1  25    Type1      Poor   FALSE
2         2  34    Type2  Improved   FALSE
3         3  28    Type1 Excellent …
Run Code Online (Sandbox Code Playgroud)

r dplyr

3
推荐指数
1
解决办法
477
查看次数

标签 统计

dplyr ×1

r ×1