R: Insert multiple rows (variable number) in data frame
问题 I have a data frame with, say, 5 rows, for 2 observables. I need to insert "dummy" or "zero" rows in the data frame so that number of rows per observable is the same (and can be bigger than N rows for longer one). E.g.: # This is what I have: x = c("a","a","b","b","b") y = c(2,4,5,2,6) dft = data.frame(x,y) print(dft) x y 1 a 2 2 a 4 3 b 5 4 b 2 5 b 6 Here's what I'd like to get, i.e. add N rows per observable to 4. Mock up df x1 = c("a","a","a","a","b","b","b","b") y1 = c(2,4,0,0,5,2,6,0)