Skip to content
Prev 366107 / 398502 Next

Computing growth rate

In your case use ifelse() as explained by Rui. 
But it can be done more easily since the fyear1 and co_code1 are synchronized.
Add a new column to df1 like this

df1$growth <- c(NA,
         ifelse(diff(df1$fyear1)==1,
                    (exp(diff(log(df1$sales1)))-1)*100,
                    NA
                    )
        )

and display df1. From your request I cannot determine if this is what you want.

regards,

Berend Hasselman