Hi, #Just to add: v<-c(3,5,8,4,9) diff(v) #[1] 2 3 -4 5 #if it is a dataframe, v1<-as.data.frame(v) lapply(v1,diff) apply(v1,2,diff)
A.K. ----- Original Message ----- From: Jorge I Velez <jorgeivanve...@gmail.com> To: Hermann Norpois <hnorp...@googlemail.com> Cc: r-help@r-project.org Sent: Monday, September 24, 2012 8:19 AM Subject: Re: [R] serial subtraction within a vector ?diff HTH, Jorge.- On Mon, Sep 24, 2012 at 9:00 PM, Hermann Norpois <hnorp...@googlemail.com>wrote: > Hello, > > I have a vector (numeric) v-> c(a,b,c,d,e) and I want to create the vector > n->c(b-a,c-b,d-c,e-d). How can I do that? > > > Thank you > Hermann > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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. ______________________________________________ R-help@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.