【问题标题】:Case_when with NA dplyrCase_when 与 NA dplyr
【发布时间】:2022-11-09 01:17:29
【问题描述】:

我想根据“标题”列向我的数据集(图像)添加一个新的列名称(title_holder)。列标题中的所有 NA 在新列“title_holder”中的值应为“no”,否则该值应为“yes”。

谢谢。

除其他外,我还尝试了以下代码:

age_average <- age %>% mutate(title_holder = case_when (!is.na(title), "no", TRUE ~ "yes")) %>%view()

有人可以帮我找出正确的代码吗?

【问题讨论】:

    标签: r


    【解决方案1】:

    我们需要

    age %>% mutate(title_holder = case_when (!is.na(title)~ "no", TRUE ~ "yes"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-24
      • 1970-01-01
      • 2020-09-16
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      相关资源
      最近更新 更多