Skip to contents

Replicates the rows of a data frame based on a grouping variable and replication counts for each group.

Usage

replicateByGroup(df, group_var, rep_list)

Arguments

df

Data frame to replicate

group_var

Name of the grouping variable in the data frame

rep_list

Vector of replication counts for each group

Value

Data frame with replicated rows

Examples

df <- data.frame(group = c("A", "B"), value = c(1, 2))
replicateByGroup(df, "group", c(2, 3))
#>   group value sampleID
#> 1     A     1       _1
#> 2     A     1       _2
#> 3     B     2       _1
#> 4     B     2       _2
#> 5     B     2       _3