[R] [FORGED] Re:  Using apply
    Jeff Newmiller 
    jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
       
    Wed Oct 31 07:22:32 CET 2018
    
    
  
In general doing vectorized calculations on larger data units is going to lead to faster computation, so it would be better in the long run if your taste could evolve to appreciate Jim's approach.
On October 30, 2018 10:03:15 PM PDT, Rolf Turner <r.turner using auckland.ac.nz> wrote:
>
>On 10/31/18 3:47 PM, jim holtman wrote:
>
>>> s2 <- apply(x*x, 2, sum)
>>> s2
>> [1]  55 330
>
><SNIP>
>
>It seems to me to be more "natural" (and perhaps more amenable to 
>generalisation) to do:
>
>     s2 <- apply(x,2,function(v){sum(v^2)})
>
>But it's probably just a matter of taste.
>
>cheers,
>
>Rolf
-- 
Sent from my phone. Please excuse my brevity.
    
    
More information about the R-help
mailing list