Re: [R] The most straightfoward way to write a function that sums over the rows of a matrix

2009-06-16 Thread David Winsemius
The apply function is the way to iterate over rows or columns of dataframes or matrices. An example would have made this process easier testing and I have given up doing that job for You might try: apply(observs, 1, function(x) Fn(par, x) ) On Jun 16, 2009, at 11:08 AM, Stu @ AGS wrote:

Re: [R] The most straightfoward way to write a function that sums over the rows of a matrix

2009-06-16 Thread Ronggui Huang
Why not just use rowSums? Ronggui 2009/6/16 Stu @ AGS : > Hello! > > > > I am trying to write a function with vector and data.frame parameters that > uses the sum() function and values from the rows of the data.frame. > > I need to pass this function as a parameter to optim(). > > > > My starting

[R] The most straightfoward way to write a function that sums over the rows of a matrix

2009-06-16 Thread Stu @ AGS
Hello! I am trying to write a function with vector and data.frame parameters that uses the sum() function and values from the rows of the data.frame. I need to pass this function as a parameter to optim(). My starting point is: observs <- data.frame(y, x1, x2, x3) Fn <- function(par,