【问题标题】:How to change and add new column with new ID names [closed]如何使用新 ID 名称更改和添加新列 [关闭]
【发布时间】:2020-12-07 20:45:00
【问题描述】:

我需要更改许多文件中的列。我有一些文件,其中我在 ID 列中的姓名写错了。我准备了两列“错误 ID”和“新 ID”的 excel 文件,现在我想在每个文件中更改它。

例如

wrong ID         new ID
CALU1            calu-1

我有将近 300 个不同的 ID。

【问题讨论】:

    标签: r excel multiple-columns


    【解决方案1】:

    我们可以在阅读后将文件保存在list中,然后使用rename_at

     library(dplyr)
     lst1 <- lapply(files, function(x) {
    
                x1 <- read.csv(x)
                x1 %>% 
                     rename_at(vars(df$`wrong ID`), ~ df$`new ID`)
                })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      • 2015-12-18
      • 2021-03-29
      • 2019-11-28
      相关资源
      最近更新 更多