使用 R 根据字符变量的值更改字符变量的值

Change value of character variables based on their value using R

我有一个包含国家名称的字符变量。对于一些,我需要更改国家名称以将其与另一个数据集合并。

如何将“Bahamas, The”更改为“Bahamas”?我试过了:

BD_WB$`Country Name`= " Bahamas, The" <- "Bahamas"

但是它把 BD_WB$Country Name 的全部内容改成了“巴哈马”。

尝试以下操作:

BD_WB$`Country Name`[which(BD_WB$`Country Name` == "Bahamas, The")] <- "Bahamas"

这会选择 Country Name 列中的值“Bahamas, The”,并仅将这些值更正为“Bahamas”。