I have wide data that I want to transform to long for. But before doing this, I want to rename all the variable column names.
The first variables in my data frame are anagraphical (id, names, etc) so the loop should run for all columns except the first 9.
Moreover, being the data is wide, I have repeated variables (that should have the same prefix) in the columns representing different years (10 years).
I was thinking at something like this:
for (i in seq(10:440)){
names(mydata)[i:i+10]<- paste("varname", 1:10, sep="_")
}
Obviously, it doesn't work. But I need something like this, with also "varname" varying with i (I need to recode about 45 variables repeated for 10 years).
I hope to have been clear.
Thanks to anyone will help!!!!!
my data look like this
id Operating_renvenue_last_yr Operating_renvenue_-1 Operating_renvenue-2 ... Fixed_assets_last_yr Fixed_assets-1 Fixed_assets-_2
ESA08005449 1973859 1983692 2028124 ... 205824 205955 208695
ESA08000820 1044971 962639 912788 ... 100355 120558 135448
ESA17000852 1005575 1035578 1055304 ... 509555 520687 705777
ESA08800450 861971 812596 765714 ... 1120587 1130458 1145200
And I want to obtain:
id OR_1 OR_2 OR_3 ... FA_1 FA_2 FA_3
ESA08005449 1973859 1983692 2028124 ... 205824 205955 208695
ESA08000820 1044971 962639 912788 ... 100355 120558 135448
ESA17000852 1005575 1035578 1055304 ... 509555 520687 705777
ESA08800450 861971 812596 765714 ... 1120587 1130458 1145200
dput(names(YourData)[1:50])- Andre Elrico