It seems to me that the simplest approach is as follows. Say you have a function as follows: dosomething <- function(x,y) 0.523*x^2 + 0.34*y Then you just use apply as follows to get your result (assuming that the first column of matrix m contains the x values and the second column contains the y values: apply(m, 1, function(x) dosomething(x[1], x[2]))
Brian Gregor, P.E. Transportation Planning Analysis Unit Oregon Department of Transportation [EMAIL PROTECTED] (503) 986-4120 -----Original Message----- > From: Bing Zhang [mailto:[EMAIL PROTECTED] > Sent: Wednesday, September 17, 2003 2:03 PM > To: r-help > Subject: [R] using matrix data for function > > > Hi All, > > I have a function, f(x,y) > I have a matrix of data, m, with the 1st column is x and the > 2nd column is y What's the best way to get f(x,y) for each > row of the matrix? I tried > result<-f(m[,1],m[,2]) but it doesn't work. > > Thanks! > > Bing ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help