I try to utilize some operations on rows in a matrix using command 'apply'
but find a problem.
First I write a simple function to normalize a vector (ignore error
handling) as follows:
normalize = function( v ) {
return( ( v-min(v) ) / ( max(v) - min(v) ) )
}
The function works fine for
yes, the matrix is symmetric.
But when I apply normalize upon rows, I expect to get the following result:
> apply( a, 1, normalize )
[,1] [,2] [,3] [,4] [,5]
[1,] 0.00 0.25 0.50 0.75 1.00
[2,] 0.00 0.25 0.50 0.75 1.00
[3,] 0.00 0.25 0.50 0.75 1.00
[4,] 0.00 0.25 0.50 0.75 1.00
[5,] 0.00 0.25
2 matches
Mail list logo