How do I translate this Matlab bsxfun call to R?
- by claytontstanley
I would also (fingers crossed) like the solution to work with R Sparse Matrices in the Matrix package.
>> A = [1,2,3,4,5]
A =
1 2 3 4 5
>> B = [1;2;3;4;5]
B =
1
2
3
4
5
>> bsxfun(@times, A, B)
ans =
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
>>
EDIT:
I would like to do a matrix multiplication of these sparse vectors, and return a sparse array:
> class(NRowSums)
[1] "dsparseVector"
attr(,"package")
[1] "Matrix"
> class(NColSums)
[1] "dsparseVector"
attr(,"package")
[1] "Matrix"
>
NRowSums * NColSums (I think) w/o using a non-sparse variable to temporarily store data.