Here is an example of adding up 2 consecutive rows, iterating through all
the row:
> x <- matrix(1:100,10)
> x
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1   11   21   31   41   51   61   71   81    91
 [2,]    2   12   22   32   42   52   62   72   82    92
 [3,]    3   13   23   33   43   53   63   73   83    93
 [4,]    4   14   24   34   44   54   64   74   84    94
 [5,]    5   15   25   35   45   55   65   75   85    95
 [6,]    6   16   26   36   46   56   66   76   86    96
 [7,]    7   17   27   37   47   57   67   77   87    97
 [8,]    8   18   28   38   48   58   68   78   88    98
 [9,]    9   19   29   39   49   59   69   79   89    99
[10,]   10   20   30   40   50   60   70   80   90   100
> sapply(seq(nrow(x)/2), function(z) sum(x[2*z-1,], x[2*z,]))
[1]  930  970 1010 1050 1090
>



On 6/20/06, markleeds@verizon.net <markleeds@verizon.net> wrote:
>
>
> uugh : i promise that this will be my last question of the day.
> i hate to constantly bother this group but it takes me time to get familar
> with all of these functions, tricks and and manipulations.
> i appreciate everyone's patience. i used too splus a lot
> but i've gotten rusty.
>
> i have a matrix of say 200 rows and 600 columns.
>
> i have a function "getprofit" that takes two series and returns a number.
>
> getprofit<-function(series1, series2) {
> do some stufff
> return(somenumber)
>
> is there a way to do something clever so that
> i call the function, getprofit, on the first two columns
> of the matrix ( where the first column is series1 and the second column is
> series2 ), then the next two columns of the matrix,
> then the next two columns of the matrix and so on and so forth return a
> 300 by 1 ( oir 1 by 300, it doesn't matter ) vector of "somenumbers".
>
> i ( maybe stupidly ) put the data in a matrix but
> now i am thinking that wasn't a good thing to do ?
> i can change it to some thing else if i have to.
>
>                                thanks
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390 (Cell)
+1 513 247 0281 (Home)

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

