[R] Computing time for matrix addition or subtraction
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Nov 13 05:47:02 CET 2006
This is slightly faster but not by much:
ad <- function(m, a) { diag(m) <- diag(m) + a; m }
R <- ad(P %*% P - t(P) - P, 1)
On 11/12/06, YONGWAN CHUN <chun.49 at osu.edu> wrote:
> Hello,
>
>
> I wonder by chance if there is a way to reduce computing time for matrix addition or subtraction. With a lot of iterations, it would be helpful to reduce a little amount time.
>
> Simple example is as below
>
> n <- 2000
> P <- matrix(rnorm(n*n),n,n)
> PP <- P %*% P
> M <- diag(n) - P
> R <- M + t(M) - diag(n) + PP
>
> I would like to reduce time in calculating R.
>
> Thanks,
>
> Yongwan
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list