[R] serial subtraction within a vector

arun smartpink111 at yahoo.com
Mon Sep 24 14:45:19 CEST 2012


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 <jorgeivanvelez at gmail.com>
To: Hermann Norpois <hnorpois at googlemail.com>
Cc: r-help at 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 <hnorpois at 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 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.
>

    [[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