-1
I have a list with some data and I need to make the moving average of the last 3 data available, what I am not able to do is to include the value of this average in the last line of my list. I’ve tried using the merge
, but is creating a list with two variables, as follows and would like the value to be added below the last row of the column x
.
x <- c(1:20)
media <- mean(tail(x, n = 3L))
x <- merge(x,media)
x y
1 19
2 19
3 19
4 19
5 19
6 19
7 19
8 19
9 19
10 19
11 19
12 19
13 19
14 19
15 19
16 19
17 19
18 19
19 19
20 19
It worked perfectly! Thank you!
– Alexandre Sanches