I've got a logical matrix and I need to multiply each column by the sum of this column using apply. For example :
> a
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
[2,] 0 0 0 0
[3,] 1 1 0 1
[4,] 1 0 0 1
> b <- colSums(a)
> b
[1] 3 2 1 3
And I want to get the following matrix :
> a
[,1] [,2] [,3] [,4]
[1,] 3 2 1 3
[2,] 0 0 0 0
[3,] 3 2 0 3
[4,] 3 0 0 3
I did it with for but since I need to apply my function to a huge dataset I need to code with apply. Thank you.