How do I translate this Matlab bsxfun call to R?
        Posted  
        
            by 
                claytontstanley
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by claytontstanley
        
        
        
        Published on 2012-09-28T20:47:26Z
        Indexed on 
            2012/09/28
            21:37 UTC
        
        
        Read the original article
        Hit count: 638
        
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.
© Stack Overflow or respective owner