Skip to contents

Add a data to itself X times by rows or columns

Usage

data_rep(., n, which = c("rows", "cols"))

Arguments

.

data frame variable

n

multiples of duplicate

which

where to append the duplicated data e.g. rows or cols

Value

the duplicated dataset store to a variable with the name of the first

Examples

# initialize p1 and p2
init(p1,p2)
p1
#> NULL
p2
#> NULL

# declare p1 and p2 as data frame
p1 <- data.frame(PK=1:10,ID2=1:10)
p2 <- data.frame(PK=11:20,ID2=21:30)

p1
#>    PK ID2
#> 1   1   1
#> 2   2   2
#> 3   3   3
#> 4   4   4
#> 5   5   5
#> 6   6   6
#> 7   7   7
#> 8   8   8
#> 9   9   9
#> 10 10  10
p2
#>    PK ID2
#> 1  11  21
#> 2  12  22
#> 3  13  23
#> 4  14  24
#> 5  15  25
#> 6  16  26
#> 7  17  27
#> 8  18  28
#> 9  19  29
#> 10 20  30

#add p1  twice by row, and resave as p1
data_rep(p1,n=2,"rows")
p1 #p1 has been updated
#>    PK ID2
#> 1   1   1
#> 2   2   2
#> 3   3   3
#> 4   4   4
#> 5   5   5
#> 6   6   6
#> 7   7   7
#> 8   8   8
#> 9   9   9
#> 10 10  10
#> 11  1   1
#> 12  2   2
#> 13  3   3
#> 14  4   4
#> 15  5   5
#> 16  6   6
#> 17  7   7
#> 18  8   8
#> 19  9   9
#> 20 10  10


#add p2  3 times by col, and resave as p2
data_rep(p2,n=3,"cols")
p2 #p2 has been updated
#>    PK ID2 PK ID2 PK ID2
#> 1  11  21 11  21 11  21
#> 2  12  22 12  22 12  22
#> 3  13  23 13  23 13  23
#> 4  14  24 14  24 14  24
#> 5  15  25 15  25 15  25
#> 6  16  26 16  26 16  26
#> 7  17  27 17  27 17  27
#> 8  18  28 18  28 18  28
#> 9  19  29 19  29 19  29
#> 10 20  30 20  30 20  30