Hi all I have a part of a data set:
# A tibble: 10 × 2
id value
<dbl> <dbl>
1 1 2
2 1 2
3 1 2
4 5 2
5 6 3
6 7 0
7 8 4
8 8 4
9 9 1
10 9 1
I would like to add "1" to every subsequent value of the same ID. E.g. the first value of "id 1" is 2 while the second value of "id 1" is 3 and third value of "id 1" is 4. However, those with only 1 id (5,6,7) are left as it is. So essentially it would look like this for the first few values:
# A tibble: 10 × 2
id value
<dbl> <dbl>
1 1 2
2 1 3
3 1 4
4 5 2
5 6 3
6 7 0
7 8 4
8 8 5
9 9 1
10 9 2
Thanks in advance!
Joey
DATA
structure(list(id = c(1, 1, 1, 5, 6, 7, 8, 8, 9, 9), value = c(2,
2, 2, 2, 3, 0, 4, 4, 1, 1)), .Names = c("id", "value"), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -10L))
Expected output:
structure(list(id = c(1, 1, 1, 5, 6, 7, 8, 8, 9, 9), value = c(2,
3, 4, 2, 3, 0, 4, 5, 1, 2)), .Names = c("id", "value"), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -10L))