table

Methods

Method Reference: table.repelem

table: tblB = repelem (tblA, rows, columns)

Replicate elements of a table.

Replicates each row of the input table tblA rows times and each variable columns times, keeping the repeats of a row together, in a similar fashion to how repelem applies to a matrix. Each repeated variable takes a numbered name, x becoming x, x_1, and so does each repeated row name.

Either count may be a vector with one count per row, or per variable, as in repelem (tblA, [1; 2; 0], 1), and a count of zero drops that row or variable. Both counts must be given. A table has exactly two dimensions, so a lone count is not read as applying to both, as it is for a matrix.

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 =
  6x2 table

     Name      Grade    
    _______    _____    

    "Li"           A    
    "Diaz"         B    
    "Diaz"         B    
    "Brown"        A    
    "Brown"        A    
    "Brown"        A