[R] using matrix data for function

Jason Turner jasont at indigoindustrial.co.nz
Wed Sep 17 22:46:46 CEST 2003


On Thu, 2003-09-18 at 06:02, Bing Zhang wrote:
> 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.

That is the best way, provided your function handles vectors nicely. 
Apparently, yours doesn't.

Next best is something like apply(m,2,f)

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
+64-(0)21-343-545




More information about the R-help mailing list