table.repelem
table: tblB = repelem (tblA, sz)
table: tblB = repelem (tblA, rows, columns)
Replicate elements of a table.
Replicates elements of the input table tblA in a similar fashion
to how repelem applies to a matrix. Only two dimensions are
supported for tables.
Source Code: table
repelem repeats each row in place. With a scalar count every row is duplicated the same number of times, carrying all variable types along.
Name = string ({'Li'; 'Diaz'; 'Brown'});
Grade = categorical ({'A'; 'B'; 'A'});
T = table (Name, Grade)
T =
3x2 table
Name Grade
_______ _____
"Li" A
"Diaz" B
"Brown" A
repelem (T, 2, 1)
ans =
6x2 table
Name Grade
_______ _____
"Li" A
"Li" A
"Diaz" B
"Diaz" B
"Brown" A
"Brown" A
A vector count sets the repeat count per row — here row 1 once, row 2 twice, row 3 three times.
repelem (T, [1; 2; 3], 1)
ans =
3x2 table
Name Grade
_______ _____
"Li" A
"Diaz" B
"Brown" A