[R] Substract "previous" element

R. Michael Weylandt <michael.weylandt@gmail.com> michael.weylandt at gmail.com
Sun Oct 9 17:34:19 CEST 2011


Take a look at diff() though offhand I dont know what it does to matrices

M

On Oct 9, 2011, at 11:00 AM, Alaios <alaios at yahoo.com> wrote:

> Dear all,
> I have a matrix with data and I want to substract from every value the previous element.
> 
> Let's assume that my vector(matrix) is c<-(1,2,3,4,5)
> I want to get remove_previous c<-(0,1,2,3,4).
> 
> How I can do that efficiently in R?
> 
> I would like to thank you in advance for your help
> B.R
> Alex
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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