Displaying 1 result from an estimated 1 matches for "dividebymean".
2010 Jun 01
2
Problem using apply
...I want when doing stuff on rows.
Let's say I want to divide the rows of matrix by their mean, the below show
you get the same result weather you use 1 or 2, i.e. same result for columns
than for means..:(
Thanks a lot for the help,
m = matrix( c(1,4,7,4,5,8,7,8,9), nrow = 3 )
divideByMean = function( v ){
return( v/mean(v))
}
rowMean = c( mean( m[1,]),mean( m[2,]),mean( m[3,]) )
rowMean
colMean = c( mean( m[,1]),mean( m[,2]),mean( m[,3]) )
colMean
m
print("ByRow")
apply( m, 1, divideByMean)
print("ByCol")
apply( m, 2, divideByMean)...