I have a list of column names which I do NOT want to change colsNotRename
.
All the other columns I do want to prefix. A way to do it in BaseR would be e.g.:
xx <- data.frame(A = 1:3, B = 3:5, Unknown = c("A","B","C"))
colsNotRename <- c("A","B")
cols <- !colnames(xx) %in% colsNotRename
colnames(xx)[cols] <- paste0("unknown.", colnames(xx)[cols])
or :
xx <- setNames(xx, c(colnames(xx)[!cols] , paste0("unknown.", colnames(xx)[cols])))
I am looking for an solution to this problem with dplyr::rename_