[R] Basic matrix math question and avoiding additional memory allocation?
David Reiss
dreiss at systemsbiology.org
Tue Feb 2 21:37:14 CET 2010
I was not able to find this being specifically addressed previously,
so I thought I'd try starting a new thread:
I am dealing with a bunch of big matrices and basic mathematics, such as
x <- x + y * 3
where x and y are large matrices of the same dimension. I now realize
that when I perform the above expression, I am allocating two new
matrices of the same kind.
However, this expression
x[,] <- x[,] + y[,] * 3
seems do the operations in-place and thus should avoid additional
memory allocation (at least from what I gather using tracemem()).
Is this actually what is happening? Why is it that when I look at y
after performing the above expression, it hasn't changed?
I would greatly appreciate hearing any insights from experienced R
users or developers.
Also additional memory saving tricks would also be a great addition to
this thread.
Thanks.
-David
More information about the R-help
mailing list