Re: [R] Manual sort in a for loop

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 25 Mar 2009 14:21:25 -0400

I assume you need to use 'get' to retrieve the value:

table_year=1951
for (i in (paste("arunoff_",year,"_temp",sep=""))) {

         assign(paste("arunoff_",table_year, sep=""),get(paste("arunoff_",table_year,"_temp"))[c(10,7,9,5,4,12,1,3,2,8,11,6),])

         table_year = table_year+1
         }

On Wed, Mar 25, 2009 at 1:58 PM, Steve Murray <smurray444_at_hotmail.com> wrote:
>
> 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]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 25 Mar 2009 - 17:29:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 25 Mar 2009 - 17:30:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive