Repeat rows
repeat_rows.RdThis function repeats the rows of a matrix, data.frame or tibble by a given number of times.
Arguments
- x
A matrix, data.frame or tibble
- n
The number of times to repeat each row
Value
A matrix, data.frame or tibble depending on the type of the input
Examples
repeat_rows(matrix(1:4, nrow = 2), 2)
#> [,1] [,2]
#> [1,] 1 3
#> [2,] 1 3
#> [3,] 2 4
#> [4,] 2 4
repeat_rows(tibble::tibble(a = 1:2, b = 3:4), 2)
#> # A tibble: 4 × 2
#> a b
#> <int> <int>
#> 1 1 3
#> 2 1 3
#> 3 2 4
#> 4 2 4
repeat_rows(data.frame(a = 1:2, b = 3:4), 2)
#> a b
#> 1 1 3
#> 1.1 1 3
#> 2 2 4
#> 2.1 2 4