Hello.

This is my dataset.

 id order(t) A Previous A  1 1 0 NA  1 2 1 0  1 3 1 1  1 4 0 1  1 5 0 0  2 1
1 NA  2 2 0 1  3 1 1 NA  3 2 1 1  3 3 0 1  3 4 0 0

Id is individual. (ex.1=Mike, 2=Sandy)
Order(t) is order of individual's behavior.
A is idividual's behavior(ex. buying is 1 otherwise 0) at order.
Previous A is lag value(order-1) of A

I want to caculate C

C's function is that

C(t)=B*C(t-1)+(1-B)*Previous A

My expected result is

 id order A Previous A C  1 1 0 NA 0  1 2 1 0 0  1 3 1 1 0  1 4 0 1 0.5  1 5
0 0 0.25  2 1 1 NA 0  2 2 0 1 0.5  3 1 1 NA 0  3 2 1 1 0.5  3 3 0 1 1  3 4 0
0 0.5

The point is that I shoud utilize C(t-1) value to get C(t). Also, I should
consider individual(group condition)

So, how I can handle this problem in R.

Thank you.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to