Skip to content

Is there a funct to sum differences?

2 messages · arthur brogard, Jeff Newmiller

#
I've been looking but I can't find a function to sum difference.

I have this code:

 
rates$thisone <- c(diff(rates$Int), NA)
rates$nextone <- c(diff(rates$Int, lag=2), NA, NA)
rates$lastone <- (rates$thisone + rates$nextone)


It is looking down one long column of numbers.

It sums the difference between the first two and then between the first and third and so on.

Can it be made to automatically sum the difference between the first and subsequent to the end of a list?
#
Could you make your example reproducible? That is, include some sample input and output. You talk about a column of numbers and then you seem to work with named lists and I can't reconcile your words with the code I see.