Bulk Rename Variables in R: Quick Guide

In the R language, you can use the names() function to rename variables in bulk. The specific steps are as follows:

  1. Create a vector containing the original variable names.
  2. Create a vector with new variable names.
  3. list_of_names()

The code example is provided as follows:

# 创建一个包含原变量名的向量
old_names <- c("var1", "var2", "var3")

# 创建一个包含新变量名的向量
new_names <- c("new_var1", "new_var2", "new_var3")

# 使用names()函数将新变量名赋给原变量名向量
names(old_names) <- new_names

# 查看修改后的变量名
print(old_names)

After implementing the above code, the variable names in the original vector old_names will be changed to the corresponding variable names in the new vector new_names.

bannerAds