Dear R helpers

Wish you all a very Happy and Prosperous New Year 2011.

I have following query.

country = c("US", "France", "UK", "NewZealand", "Germany", "Austria", "Italy", "Canada")

Through some other R process, the result.csv file is generated as

result.csv

     var1   var2  var3  var4    var5    var6   var7   var8
1      25     45    29    92     108     105     65     56
2      80    132    83    38      38      11     47     74
3     135     11    74    56      74      74     74     29

                  
I need the country names to be column heads i.e. I need an output like

> result_new
    US    France     UK   NewZealand      Germany      Austria      Italy     Canada
1   25          45      29                  92             108            105        65             56
2   80        132      83                  38               38              11        47             74
3  135         11      74                  56               74              74        74             29
                  

The number of countries i.e. length(country) matches with total number of variables (i.e. no of columns in 'result.csv').                  
                                    
One way of doing this is to use country names as column names while writing the 'result.csv' file. 

write.csv(data.frame(US = ..........., France = .......), 'result.csv', row.names = FALSE)


However, the problem is I don't know in what order the country names will appear and also there could be addition or deletion of some country names. Also, if there are say 150 country names, the above way (i.e. writing.csv) of defining the column names is not practical. 

Basically I want to change the column heads after the 'result.csv' is generated.

Kindly guide.

Regards

Vincy




	[[alternative HTML version deleted]]

