sumsquared | R Documentation |
Calculate sum(x^2)
, but faster when the number of
elements exceeds 1000.
x |
double, integer, or logical vector/matrix |
A numerical scalar
x <- rnorm(10000)
sumsquared(x)
# Compare speed
microbenchmark::microbenchmark(
cpp = {sumsquared(x)},
r = {sum(x^2)}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.