[R] question on graphs and finding area under a curve

Tuszynski, Jaroslaw W. JAROSLAW.W.TUSZYNSKI at saic.com
Tue Aug 2 15:22:57 CEST 2005


How about:

trapz = function(x, y) 
{ # computes the integral of y with respect to x using trapezoidal
integration. 
  idx = 2:length(x)
  return (as.double( (x[idx] - x[idx-1]) %*% (y[idx] + y[idx-1])) / 2)
} 

Jarek
====================================================\=======

 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">   \
 Jaroslaw.W.Tuszynski at saic.com                     `    \


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Renuka Sane
Sent: Tuesday, August 02, 2005 8:51 AM
To: r-help at stat.math.ethz.ch
Subject: [R] question on graphs and finding area under a curve

Question on graphs:

The default case for drawing a graph in R, is where a little space is left
on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) --
there will be some space between the edge of the x-axis and where 0 is
placed. If I want 0 on the edge, how do I do it in R?

Area under the curve:

I have a 45 degree line and a curve above or below it. Is there a way in R
to find the area between the two?

Thanks,
Renuka

--
Renuka Sane
http://www.nyx.net/~rsane

	[[alternative HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list