I am trying to use the apply family functions to improve the efficiency of my code, though it is a bit hard for me to find sometimes the solutions with these functions.
The problem that I want to solve is:
I have a matrix of replicated random generated data, e.g. if I have two controls with 100 observations and replicated the data 100 times then I am going to have a 100x2000 matrix (odd rows have the control x1 and even rows control x2). Then I want to multiply a vector of order two in this example (q in general) by each observation of the random generated data, so at the end I am going to obtain a 100x1000 matrix.
A solution to the above problem is given by the following code without using apply family functions and is efficient I think as well, but I would like to know if there is another way because I think the other way can solve similar problems that I have and this particular way cannot solve.