Replicate rows of a data frame by group
replicateByGroup.Rd
Replicates the rows of a data frame based on a grouping variable and replication counts for each group.
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
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