[R] matrix and a function - apply function
ADias
diasandre at gmail.com
Wed Feb 2 15:12:01 CET 2011
Hi
I have this function and this matrix:
function(x,y) x+y/x
m<-matrix(c(1,2,4,2,10,8),3,2)
> m
[,1] [,2]
[1,] 1 2
[2,] 2 10
[3,] 4 8
each row represent a point (x,y) in a chart and I want via my fucntion to
calculate the image in order to get this results:
for point (1,2) I would get 1+2/1 = 3
for point (2,10) I would get 2+10/2 = 7
for point (4,8) I would get 4+8/4 = 6
I have tried using sapply here but I get this:
> sapply(m,function(x,y) x+y/x)
Error in y/x : 'y' is missing
what I am doing wrong?
thanks
ADias
--
View this message in context: http://r.789695.n4.nabble.com/matrix-and-a-function-apply-function-tp3254271p3254271.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list