I am running double forloop for two matrices. but one matrix has around 90,000 rows.
it is too slow in R. so, I would like to take apply function for this if possible.
- One matrix has 90,000 X 1 column with string information per row. e.g 1row value(ID) AAAA12
- The other matrix has also around 90,000 but a bit more than 90,000 X 2 columns, so for one row(ID) has AAAA23 in 1st column and corresponding month information e.g AAAA23 Jan
And 2nd row, AAAA12 Feb …etc
So, I would like to merge one column of matched month information from 2nd matrix to 1st mat.
1st row of output mat is going to be AAAA12 Feb. instead of using for loop, how can I generate such a matrix quickly?
Any input will be helpful.
The following might do the trick:
Which gives you
…And then timing it on around 90000 rows shows it takes around 0.04 seconds: