Hi,
I'd like to take difference for a sequence a between a_i and a_i-2, for
instance,
a<-c(2,3,4,8,1)
I need (2, 5, -3) as a result. If not using a for loop, can anyone help me?
Thanks a lot.
Dot
--
View this message in context:
http://www.nabble.com/R-help--how-to-take-difference-in-next-two-
On 8/11/2008 11:26 AM, dott wrote:
Hi,
I'd like to take difference for a sequence a between a_i and a_i-2, for
instance,
a<-c(2,3,4,8,1)
I need (2, 5, -3) as a result. If not using a for loop, can anyone help me?
Thanks a lot.
Dot
a <- c(2,3,4,8,1)
diff(a, lag=2)
[1] 2 5 -3
?diff
--
Chuc
Here are a couple of ways:
> tail(a, -2) - head(a, -2)
[1] 2 5 -3
> c(ts(a) - lag(ts(a), -2))
[1] 2 5 -3
On Mon, Aug 11, 2008 at 11:26 AM, dott <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'd like to take difference for a sequence a between a_i and a_i-2, for
> instance,
> a<-c(2,3,4,8,1)
> I nee
p@r-project.org
Subject: [R] R-help? how to take difference in next two elements
Hi,
I'd like to take difference for a sequence a between a_i and a_i-2, for
instance,
a<-c(2,3,4,8,1)
I need (2, 5, -3) as a result. If not using a for loop, can anyone help me?
Thanks a lot.
Dot
--
View this m
Thanks all for the help, that is done.
Gabor Grothendieck wrote:
>
> Here are a couple of ways:
>
>> tail(a, -2) - head(a, -2)
> [1] 2 5 -3
>> c(ts(a) - lag(ts(a), -2))
> [1] 2 5 -3
>
>
> On Mon, Aug 11, 2008 at 11:26 AM, dott <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> I'd like to take d
5 matches
Mail list logo