I want to duplicate all rows with treatment C 3 times. How do I do that?
A <- sample(1:100,9)
B <- sample(1:100,9)
trt <- rep(c("A", "B", "C"),3)
df <- data.frame(trt, A, B)
> df
trt A B
1 A 82 57
2 B 76 2
3 C 12 82
4 A 87 25
5 B 64 86
6 C 74 89
7 A 4 80
8 B 31 13
9 C 39 88
I have tried this but it doesn't get right!
as.data.frame(lapply(df, rep, 2))
if (df[df$trt=="C",]){
data.frame(rep(df,3))
}