Suppose I have 8 variables named: DY, DZ, EA, EB, EC, ED, EE, EF.
I want them to be renamed to the followings:
Apple_total_harvest
Apple_price
Orange_total_harvest
Orange_price
Peach_total_harvest
Peach_price
Mango_total_harvest
Mango_price
In my actual dataset, I have a lot more variables to rename in the above manner. Therefore, I am wondering if I could write a for loop to accomplish the renaming task quickly and efficiently. I am thinking that I might have to create a "list" or something with the parts which are common to each variable name i.e. total harvest and price and create another separate list with fruits' names. Then somehow link the fruits' names to parts in the first list. But I don't know how I can do this. Any help will be highly appreciated.
I want them to be renamed to the followings:
Apple_total_harvest
Apple_price
Orange_total_harvest
Orange_price
Peach_total_harvest
Peach_price
Mango_total_harvest
Mango_price
In my actual dataset, I have a lot more variables to rename in the above manner. Therefore, I am wondering if I could write a for loop to accomplish the renaming task quickly and efficiently. I am thinking that I might have to create a "list" or something with the parts which are common to each variable name i.e. total harvest and price and create another separate list with fruits' names. Then somehow link the fruits' names to parts in the first list. But I don't know how I can do this. Any help will be highly appreciated.
Comment