On 16-11-2012, at 15:50, e-letter wrote:
> Readers,
>
> If a vector consists of:
>
> 10
> 20
> 30
>
> how to create a new vector based upon the results of calculations to
> the elements, e.g. addition of successive elements, so that a new
> vector would be:
>
> 30
> 50
>
> i.e. 10+20, then 2
Hello,
Try the following.
x <- 1:3*10
idx <- seq_along(x)[-1]
rowSums(cbind(x[idx], x[idx-1]))
Hope this helps,
Rui Barradas
Em 16-11-2012 14:50, e-letter escreveu:
Readers,
If a vector consists of:
10
20
30
how to create a new vector based upon the results of calculations to
the elements,
Try this:
x <- c(10, 20, 30)
head(x, -1) + tail(x, -1)
I hope it helps.
Best,
Dimitris
On 11/16/2012 3:50 PM, e-letter wrote:
> Readers,
>
> If a vector consists of:
>
> 10
> 20
> 30
>
> how to create a new vector based upon the results of calculations to
> the elements, e.g. addition of suc
Readers,
If a vector consists of:
10
20
30
how to create a new vector based upon the results of calculations to
the elements, e.g. addition of successive elements, so that a new
vector would be:
30
50
i.e. 10+20, then 20+30, etc.?
__
R-help@r-projec
4 matches
Mail list logo