【问题标题】:How to make an if-else statement without error?如何在没有错误的情况下做出 if-else 语句?
【发布时间】:2019-01-04 12:59:51
【问题描述】:

我必须做一个 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”、“其他”、cancerKode)。

【问题讨论】:

    标签: r if-statement dplyr


    【解决方案1】:
    other_vector <- c("DC911", "DC833", "DC830", "DC910", "DC921", "DC831", "DC859","DC919", "DC911B")
    df4x%>%
      mutate(sygdomsgruppex = ifelse(cancercode %in% other_vector, "Other", cancercode))
    

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-05
      • 2020-05-06
      相关资源
      最近更新 更多