[R] Fastest way to extract rows of smaller matrix many times by index to make larger matrix? and multiply columsn of matrix by vector
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Tue Sep 14 09:49:00 CEST 2021
That is about as fast as it can be done. However you may be able to avoid doing it at all if you fold V2 into a matrix instead. Did you mean to use matrix multiplication in your calculation of M3?
On September 13, 2021 11:48:48 PM PDT, nevil amos <nevil.amos using gmail.com> wrote:
>Hi is there a faster way to "extract" rows of a matrix many times to for a
>longer matrix based in a vector or for indices than M[ V, ]
>I need to "expand" ( rather than subset) a matrix M of 10-100,000 rows x
>~50 columns to produce a matrix with a greater number (10^6-10^8) of rows
>using a vector V containing the 10^6 -10^8 values that are the indices of
>the rows of M. the output matrix M2 is then multiplied by another vector V2
>With the same length as V.
>Is there a faster way to achieve these calculations (which are by far the
>slowest portion of a function looped 1000s of times? than the standard M2
><- M[ V, ] and M3<-M2*V2, the two calculations are taking a similar time,
>Matrix M also changes for each loop.
>x = 10^7
>times=5,unit = "ms"))
>thanks for any suggestions
> [[alternative HTML version deleted]]
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
Sent from my phone. Please excuse my brevity.
More information about the R-help