Displaying 1 result from an estimated 1 matches for "returnfunct".
Did you mean:
returnfunc
2011 Feb 07
1
how to return multipy matrix in a function
Hello
I have a 100*100 matrix which is from a intensive computation, e.g. mat. Is there any method/function that return the max of every row and the subscript of maximum value simultaneously
#define the function
> returnfunction<-function(x){
+ value<-apply(x,1,max)
+ index<-apply(x,1,which.max)
+ }
> mat<-matrix(c(3,5,7,2,1,10,4,3,2),3)#initilize the matrix for test
> mat
[,1] [,2] [,3]
[1,] 3 2 4
[2,] 5 1 3
[3,] 7 10 2
> returnfunction(mat)$value
Error in returnfu...