Re: [R] Problem with command apply

2010-07-20 Thread Berend Hasselman
On 20-07-2010, at 20:30, litao.ext [via R] wrote: > 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 >

Re: [R] Problem with command apply

2010-07-20 Thread litao.ext
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

[R] Problem with command apply

2010-07-20 Thread litao.ext
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

Re: [R] Problem with command apply

2010-07-20 Thread Berend Hasselman
litao.ext wrote: > > 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) )