-3

I have been trying to understand integration in R and I have come across a code that looks like this:

Lambda=function(t) integrate(f=lambda,lower=0,upper=t)$value

What does $value mean here? What's the '$' sign doing? It's not explained anywhere in the help or on the internet. Please help.

14thTimeLord
  • 363
  • 1
  • 14

1 Answers1

2

From ?integrate (bold is mine).

Value:

A list of class ‘"integrate"’ with components

value: the final estimate of the integral.

abs.error: estimate of the modulus of the absolute error.

subdivisions: the number of subintervals produced in the subdivision process.

message: ‘"OK"’ or a character string giving the error message.

call: the matched call.

In other words, integrate returns an object of class "integrate", of which element value contains the estimate of the integral.

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • yes I saw that too but I am struggling to understand how does `$` work? And also, how important is it to call "value" at the end? – 14thTimeLord Apr 20 '18 at 11:23
  • 2
    That's very [basic R subsetting](http://adv-r.had.co.nz/Subsetting.html) of `list` elements. The return object of `integrate` is a `list`; you can subset a `list`'s elements with `$name_of_list_element`. Take a look at the `integrate` return object with `str`. – Maurits Evers Apr 20 '18 at 11:31
  • You're welcome @RTomar – Maurits Evers Apr 20 '18 at 11:50