How to append a string to subset of variable names in R?
问题 I am trying to alter a select few of my variable names in a data frame. How can I do this without typing each of the old names and each of the new names? I thought the code below might work but it hasn't. I am trying to append "Econ" to each of the existing names identified in the data frame. names(wb.misc)[3,13,14,20,22,47,61,62,64,68,73] <- paste("Econ", names(wb.misc)[3,13,14,20,22,47,61,62,64,68,73], sep = "-") 回答1: You need to put c() around the indices names(wb.misc)[c(3,13,14,20,22,47