重命名dplyr中的错误:名称必须唯一

时间:2020-04-28 13:18:23

标签: r dplyr

尽管dplyr::rename具有唯一的名称,但它会中断并显示“错误:名称必须唯一”。我知道我可以选择使用其他方法重命名,例如:

rename <- function(dat, oldnames, newnames) 
{  datnames <- colnames(dat)
   datnames[which(datnames %in% oldnames)] <- newnames
   colnames(dat) <- datnames
   dat
 }

这是我的代码:

df1 <- dplyr::rename(df,
  "Language1"="Language",
  "RESPAge"="Age...31",
  "ADMIN1Name"="ADM1_NAME",
  "RESPSex"="Gender...42",
  "HHSize"="RspIsHoH",
  "HWaterSRC"="WaterSource",
  "NoteFCS"="Note FCS",
  "FCSStap"="Staples",
  "FCSPulse"="Pulses",
  "FCSDairy"="Dairy",
  "FCSPr"="Proteins",
  "FCSVeg"="Veg",
  "FCSFruit"="Fruits",
  "FCSFat"="Fats",
  "FCSSugar"="Sugars",
  "noterCSI"="note_Rcsi",
  "rCSILessQlty"="LessExpensiveFood",
  "rCSIBorrow"="BorrowOrHelp",
  "rCSIMealSize"="LimitPortionSize",
  "rCSIMealNb"="ReduceNumMeals",
  "rCSIMealAdult"="RestrictConsumption")

但是我想为此使用dplyr。我认为这是由于其他加载的软件包而引起的冲突,并且仅尝试加载readxl(用于读取数据)和dplyr,但它没有改变结果。

0 个答案:

没有答案