0

This is just as example on how we can create a new col in data which is just calculated from another col.

data$percentage <- with(data, (p*100))

I want to create a col which is a difference in value between this and the last row.

Something like this: data$diff_p <- with(data, (p[this_row] - p[this_row - 1]))

I know I can iterate the whole data in a for loop and get it done in some lines.

Is there a simpler way?

thevikas
  • 1,618
  • 1
  • 14
  • 31

0 Answers0