I am trying to calculate the percentage change between two points in R in the form:
(X_(i+1) - X_(i))/(X_(i))
Here is what I came up with so far:
However, to complete this task in R, I had to bind NA to avoid:
Error in \`$<-.data.frame\`(\`*tmp*\`, "Change", value = c(0.00248221082243916, : replacement has 4616 rows, data has 4617
With this addition, the operation is performed and aligned with what I calculated, it should be on paper.
Is there a way that I should not add NA?
source share