r - 如何在没有错误的情况下做出 if-else 语句?
问题描述
我必须做一个 if 语句,但它说错误。我有一个名为cancercode
. 我希望不等于下面所述代码的代码在数据框中声明为“其他”。
df6 <- df4x%>%
mutate(sygdomsgruppex = ifelse(cancercode != "DC911", "DC833", "DC830",
"DC910", "DC921", "DC831", "DC859","DC919", "DC911B",
"Other", cancercode))
这段代码给了我这个错误:
mutate_impl(.data, dots) 中的错误:
评估错误:未使用的参数(“DC910”、“DC921”、“DC831”、“DC859”、“DC919”、“DC911B”、“other”、cancerKode)。
解决方案
other_vector <- c("DC911", "DC833", "DC830", "DC910", "DC921", "DC831", "DC859","DC919", "DC911B")
df4x%>%
mutate(sygdomsgruppex = ifelse(cancercode %in% other_vector, "Other", cancercode))
推荐阅读
- r - 如何在 R Markdown 中包含一个函数
- corda - 在corda中跟踪保险库更新
- json - 对 json 数组使用 jq 选择操作
- javascript - 未捕获的 RangeError:`options.awareOfUnicodeTokens` 必须设置为 `true` 才能在日期选择器中使用 `YYYY`
- swift - AVFoundation 从蓝牙耳机录制和播放
- node.js - 是数据库吗?我怎么读?
- laravel - 如何查看公共存储上的图像
- javascript - 如何在角度模板中并排打印两个数组?
- python - 我需要以特定方式排列我的列表 - python
- matrix - 如何解决涉及行列式的Maxima中的矩阵方程?