[R] Fastest way to extract rows of smaller matrix many times by index to make larger matrix? and multiply columsn of matrix by vector
Leonard Mada
|eo@m@d@ @end|ng |rom @yon|c@eu
Tue Sep 14 15:46:46 CEST 2021
Hello Nevil,
you could test something like:
# the Matrix
m = matrix(1:1000, ncol=10)
m = t(m)
# Extract Data
idcol = sample(seq(100), 100, TRUE); # now columns
for(i in 1:100) {
m2 = m[ , idcol];
}
m2 = t(m2); # transpose back
It may be faster, although I did not benchmark it.
There may be more complex variants. Maybe it is warranted to try for
10^7 extractions:
- e.g. extracting one row and replacing all occurrences of that row;
Sincerely,
Leonard
========
It seems I cannot extract digested mail anymore. I hope though that the
message is processed properly.
More information about the R-help
mailing list