Skip to content
Prev 309655 / 398503 Next

Loop over several Variables, add on question

Hi
No documentation for ?rename? in specified packages and libraries:
you could try ???rename?
Which rename function do you use? plyr, reshape, ...


So I thought I simply extend to the following and the loop will be
Maybe the mistake is that you did not read any R basics. What do you expect following command shall do?

c(paste0("y", 1:5) = paste0("tiy", 1:5))

c expects several values and put them together to one object. You tried to fool it with 

paste0("y", 1:5) = paste0("tiy", 1:5)

but above statement try to put result of paste0("tiy", 1:5) to paste0("y", 1:5) which I believe is not what do you want and which does not work either.

For renaming names of unstated object ti you probably will be better with some grep construction.

something like

vec<-paste0("y", 1:5)
vec
[1] "y1" "y2" "y3" "y4" "y5"

vec[grep("y",vec)]<- paste0("tiy", 1:5)
vec
[1] "tiy1" "tiy2" "tiy3" "tiy4" "tiy5"

Regards
Petr