lundi 18 juillet 2016

R: Loop if condition (w. Yearqtr and numeric)

i got a trouble to write a loop evaluating quarters and perfroming calculation if the condition is met.

Data:

Quarter  Value*
Q1 2014  50
Q2 2014  120
Q3 2014  190
Q4 2014  290

*Values are cummulative adding result from Q1 to Q2, Q2 to Q3 etc.

desired values after loop adjustment:

Quarter  Value*
Q1 2014  50
Q2 2014  70
Q3 2014  70
Q4 2014  100

str()
Quarter - yearqtr
Value - num. 

Thanks!!

Michal

Aucun commentaire:

Enregistrer un commentaire