V
V
Vlad-M2021-09-14 23:12:48
Arrays
Vlad-M, 2021-09-14 23:12:48

How to repeat an array N times?

6140ff5d87447956134607.png
In the AG column, the original array (AG2:AG10) , in the AH column, the array that I want to get at the output (the array in the AG column is duplicated 3 times). BUT when I use a large database or display a lot of value, errors appear on the limit of formulas.

Is there a workaround or a ready script?
Taking into account that the input array is not less than 3000 lines, and the output array is 40000 lines long.

The formulas that I tried give errors:
=TRANSP(split(REPEAT(join(";",AG2:AG10)&";",9999),";"))
The number of characters as a result of the REPT function exceeds the limit (32000).
or
=TRANSP(split(REPEAT(join(";",AG2:AG20000)&";",11),";"))
The number of characters resulting from the JOIN function exceeds the limit (50000).

=ArrayFormula(TRANSPOSE(SPLIT(REPEAT(CONCATENATE(AG2:AG10&"~"),1000),"~")))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
idShura, 2021-09-15
@idShura

=TRANSPOSE(split(rept(join(";";AG:AG)&";";3);";"))
1. Range of cells (array)
2. How many times to repeat
61419ea3d7b61141766349.png

G
Grigory Boev, 2021-09-15
@ProgrammerForever

/**
* Дублирует массив
* Telegram - @ProgrammerForever
*
* @param {Range} arr Массив
* @param {number} count Сколько раз дублировать. По умолчанию 1
* @param {boolean} isFilter Указывает, нужно ли фильтровать строки исходного массива
* @param {number} column Номер столбца по которому надо фильтровать строки. По умолчанию 1.
* @return Дублированный массив
* @customfunction
*/
function array_repeat(arr, count=1, isFilter, column=1) {  
  if (isFilter){
    column = -1+column;
    arr = arr.filter(row=>row[column]);
  };

  // Вариант 1
  /*
  let outData = [];
  for(let i=0; i<=count; i++){
      outData = [...outData, ...arr];
  };
  */

  // Вариант 2, должен работать шустрее
  let outData = new Array(arr.length*count);
  for(let i=0; i<=arr.length*count; i++){
      outData[i]=arr[i%arr.length];
  };

  return outData;
}

At least 25k rows are produced by the
Demo Table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question