[R] calculate slope of line

(Ted Harding) Ted.Harding at manchester.ac.uk
Fri Jul 23 13:10:27 CEST 2010


On 23-Jul-10 09:46:28, Katrin Fleischer wrote:
> Dear All,
> I fear that this is a really easy question but I do seem to go
> around in circles..
> I have 2 points on a plot and would like to calculate the slope
> of the line drawn through these 2 points.
> 
> that cant be so hard?!
> 
> Thank you in advance,
> Katrin

  (y2 - y1)/(x2-x1)

or, if X=c(x1,x2) and Y=c(y1,y2),

  diff(Y)/diff(X)

either of which is shorter than

  lm(Y ~ X)$coeff[2]              ##  !! :)

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 23-Jul-10                                       Time: 12:10:24
------------------------------ XFMail ------------------------------



More information about the R-help mailing list