[R] Slope between two points
baptiste.auguie at googlemail.com
Thu Oct 8 11:29:18 CEST 2009
Like this perhaps?
> slope = diff(y) / diff(x)
num [1:499] 1.5068 -1.8406 2.1745 0.0676 -2.6088 ...
2009/10/8 FMH <kagba2006 at yahoo.com>:
> Dear All,
> Let 499 piece-wise lines were buit up by 500 pair of observations, via R code below.
> x <- 1:500
> y <- rnorm(500)
> plot(x, y, type = 'b')
> I was trying to compute all the slopes for the lines which were connected between two adjacent points. For instance, slopes of lines between first and second points, second and third points, and so on, until between points 499 and 500, respectively, but sadly, i never found a suitable function do this computatation efficiently.
> Could someone please advice me on doing this?
> Thank you
> R-help at r-project.org mailing list
> 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