Expand data.frame by creating duplicates based on group condition (2)
Starting from @AndrewGustar answer/code: Expand data.frame by creating duplicates based on group condition 1) What about if I have the input data.frame with ID values not in sequence and that can also duplicate theirselves? Example data.frame: df = read.table(text = 'ID Day Count Count_group 18 1933 6 11 33 1933 6 11 37 1933 6 11 18 1933 6 11 16 1933 6 11 11 1933 6 11 111 1932 5 8 34 1932 5 8 60 1932 5 8 88 1932 5 8 18 1932 5 8 33 1931 3 4 13 1931 3 4 56 1931 3 4 23 1930 1 1 6 1800 6 10 37 1800 6 10 98 1800 6 10 52 1800 6 10 18 1800 6 10 76 1800 6 10 55 1799 4 6 6 1799 4 6 52 1799 4 6 133 1799