[R] Is there a funct to sum differences?

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Sat Dec 24 03:55:59 CET 2016


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. 
-- 
Sent from my phone. Please excuse my brevity.

On December 23, 2016 3:40:18 PM PST, arthur brogard via R-help <r-help at r-project.org> wrote:
>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?
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list