[R] Manual sort in a for loop

Steve Murray smurray444 at hotmail.com
Wed Mar 25 18:58:25 CET 2009


Dear all,

I am trying to manually re-sort rows in a number of tables. The rows aren't sorted on any particular values but are simply ordered by user choice (as shown by the row numbers in the code). I have been able to carry out each re-arrangement without the use of the 'for' loop, but cannot seem to successfully execute the statements when incorporated into the loop. The code I have is as follows:

table_year=1951
for (i in (paste("arunoff_",year,"_temp",sep=""))) {
          assign(paste("arunoff_",table_year, sep=""),paste("arunoff_",table_year,"_temp")[c(10,7,9,5,4,12,1,3,2,8,11,6),])
          table_year = table_year+1
          }


The error I get is:

Error in paste("arunoff_", table_year, "_temp")[c(10, 7, 9, 5, 4, 12,  : 
  incorrect number of dimensions

...depsite this not occurring when I do each table individually (so it can't be a case of there not being enough rows, as> dim(arunoff_1951_temp) gives [1] 12 11

I have a feeling that it may be a syntax error, possibly between 'temp' and the square bracket, but I can't be sure of this.


Any solutions or advice offered would be gratefully received.

Many thanks,

Steve

_________________________________________________________________
[[elided Hotmail spam]]




More information about the R-help mailing list