In my data set, I want to rename my column number 56 to 80. Instead of going manually, I created a list of names that I want the new names to be set as. Then I run a for loop which runs without any error however every single column gets renamed as the last value in the list I created. Any suggestion on what am I doing wrong here. Please see below my code:-
To create the list:-
mylist <- list("Jun-20", "Jul-20", "Aug-20", "Sep-20", "Oct-20",
"Nov-20", "Dec-20", "Jan-21", "Feb-21", "Mar-21", "Apr-21",
"May-21", "Jun-21", "Jul-21", "Aug-21", "Sep-21", "Oct-21",
"Nov-21", "Dec-21", "Jan-22", "Feb-22", "Mar-22", "Apr-22",
"May-22", "Jun-22")
And then I run the for loop:-
for (j in 56:80) {
for (i in 1:length(mylist)) {
names(CNS7)[j] <- mylist[[i]]
}
}
Here the j values are the column range (56 to 80) which I want to rename. My end result comes as all the columns from 56 to 80 gets renamed as "Jun-22".