【问题标题】:Why does the replace function throw an error?为什么替换函数会抛出错误?
【发布时间】:2022-08-19 20:51:12
【问题描述】:

我试图用 0 替换数据中特定列中的缺失值。

这是我的代码:

ue <- ue %>%
  select(ost, west, sued, sued.ost, sued.west, ost.west, gesamtes_haus)%>% 
  replace_na(0)

当我运行它时,我收到一条错误消息:错误:\'replace\' 必须是一个列表。

这里有什么问题?

    标签: dplyr replace missing-data


    【解决方案1】:

    replace_na 需要您要替换的列的列表。尝试

    ue %>% 
        select(ost, west, sued, sued.ost, sued.west, ost.west, gesamtes_haus) %>%
        replace_na(list(ost = 0, west = 0, sued = 0, sued.ost = 0, sued.west = 0, ost.west = 0, gesamtes_haus = 0))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      相关资源
      最近更新 更多