How to replicate whole data frame and add it in the original one in R?

The replicates of a data frame in R can be created with the help of sapply function, to set the number of times we want to repeat the data frame we can use rep.int,times argument. For example, if we have a data frame df and we want to create 5 replicates of df and add them in the original then sapply(df,rep.int,times=5) can be used.

Example

sapply(df,rep.int,times=5)

Output

      x1          x2       x3    x4
[1,] 20.84538 9.486324 2.961236 967.9296
[2,] 23.29721 5.344792 3.044849 960.2204
[3,] 20.55978 6.064207 3.005293 1086.9639
[4,] 20.66044 8.436004 2.892010 1029.8222
[5,] 19.81347 9.277129 2.980567 1018.0453
[6,] 20.84538 9.486324 2.961236 967.9296
[7,] 23.29721 5.344792 3.044849 960.2204
[8,] 20.55978 6.064207 3.005293 1086.9639
[9,] 20.66044 8.436004 2.892010 1029.8222
[10,] 19.81347 9.277129 2.980567 1018.0453
[11,] 20.84538 9.486324 2.961236 967.9296
[12,] 23.29721 5.344792 3.044849 960.2204
[13,] 20.55978 6.064207 3.005293 1086.9639
[14,] 20.66044 8.436004 2.892010 1029.8222
[15,] 19.81347 9.277129 2.980567 1018.0453
[16,] 20.84538 9.486324 2.961236 967.9296
[17,] 23.29721 5.344792 3.044849 960.2204
[18,] 20.55978 6.064207 3.005293 1086.9639
[19,] 20.66044 8.436004 2.892010 1029.8222
[20,] 19.81347 9.277129 2.980567 1018.0453
[21,] 20.84538 9.486324 2.961236 967.9296
[22,] 23.29721 5.344792 3.044849 960.2204
[23,] 20.55978 6.064207 3.005293 1086.9639
[24,] 20.66044 8.436004 2.892010 1029.8222
[25,] 19.81347 9.277129 2.980567 1018.0453
Updated on: 2026-03-11T23:22:53+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements