 # Sum previous observations with parameters

this is ambigious, do you mean that you ran it as provided and received errors ?

``````
r<- sum_nextx(DF.NS\$Lunenburg,.5)

``````

ok, I think theres been confusion on my end as to whether the exponent was meant to be a fixed param, or an integer count of the element. this would only be a minor change

``````
sum_nextx <- function(xvec){

results <- vector(length=length(xvec))
y<-0
for (index in  seq_along(results)) {
y <-  xvec[index] + y * (1/2) ^ index
results[index] <- y
cat(index, "\t", round(y,5),"\n")
}
results
}``````

Good morning @nirgrahamuk,

I Thank you for your time and energy,
We are almost done!

We are very close to what I Expected, there is something that has to be quite clear.

I presented you two ways to make the operation.

1. In the first one (you will need row_number i as exponent stuck to 1/2):
Y_1= X_1
Y_2=X_2+ (1/2)^1 X_1
Y_3=X_3 + (1/2)^1
X_2 +(1/2)^2 * X_1
Y_4=X_4 + (1/2)^1 X_3 + (1/2)^2 X_2 + (1/2)^3 * X_1

2. In the Second one, We don't need Exponent, but ONLY 1/2 as coefficient.
Y_1 =X_1
Y_2= X_2 + (1/2) Y_1
Y_3= X_3+ (1/2)
Y_2
Y_4=X_4+ (1/2)* Y_3
Y_5= X_5+ (1/2)* Y_4
. .
. .
. .
. .
. .
. .
Y_366=X_366+ (1/2)*Y_365

And I think you chose the second way. in this case, we only have to consider the value of X and add the Half of Y on it without exponent. ONLY THAT.
look Y_1 =X_1
Y_2= X_2 + (1/2) *Y_1

We only consider the last value of Y and we take the half of it which will be summed with the current value of X.

sorry if this message seems too long, i tried to be a very clearer. We are almost done.

so then the second way omits the exponent...

``   y <-  xvec[index] + y * (1/2)  # not needed : ^ index``

Mathematically, they both are same

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.