R: rename subset of variables in data frame

后端 未结 5 2105
醉梦人生
醉梦人生 2020-12-21 15:02

I\'m renaming the majority of the variables in a data frame and I\'m not really impressed with my method.

Therefore, does anyone on SO have a smarter or faster way t

5条回答
  •  生来不讨喜
    2020-12-21 15:25

    I would use ifelse:

    names(temp.mtcars) <- ifelse(names(mtcars) %in% c("mpg", "cyl", "disp"),
                                 names(mtcars),
                                 paste("bar", names(mtcars), sep = "."))
    

提交回复
热议问题