You didn't get the reprex correct as shown in the article. It just makes it easier for other people to help you if you do.
I assume that it should be something like this:
df <- tibble::tribble(
~seq, ~date, ~sales,
1, "3/01/2017", 40,
2, "4/01/2017", 2,
3, "5/01/2017", 2,
4, "6/01/2017", 2,
5, "7/01/2017", 30,
6, "8/01/2017", 2,
7, "1/02/2017", 9,
8, "2/02/2017", 5,
9, "3/02/2017", 65,
10, "4/02/2017", 3,
11, "5/02/2017", 65
)
Which is:
# A tibble: 11 x 3
seq date sales
<dbl> <chr> <dbl>
1 1 3/01/2017 40
2 2 4/01/2017 2
3 3 5/01/2017 2
4 4 6/01/2017 2
5 5 7/01/2017 30
6 6 8/01/2017 2
7 7 1/02/2017 9
8 8 2/02/2017 5
9 9 3/02/2017 65
10 10 4/02/2017 3
11 11 5/02/2017 65
Then, this bit won't work because there z
only has three values (-1, 0, 1) but you have 11 rows (or more in the real dataset).
add_column(df, z = -1:1, w = 0) # this won't work
add_column(df, z = 0, w = 0) # this will
Which gets you here:
# A tibble: 11 x 5
seq date sales z w
<dbl> <chr> <dbl> <dbl> <dbl>
1 1 3/01/2017 40 0 0
2 2 4/01/2017 2 0 0
3 3 5/01/2017 2 0 0
4 4 6/01/2017 2 0 0
5 5 7/01/2017 30 0 0
6 6 8/01/2017 2 0 0
7 7 1/02/2017 9 0 0
8 8 2/02/2017 5 0 0
9 9 3/02/2017 65 0 0
10 10 4/02/2017 3 0 0
11 11 5/02/2017 65 0 0
This is probably a homework assignment for you, but the instructions are horrible. You should also read the reprex article as stated if you are hoping for help.