how to transform density object to function
I would like to use the output of the density() object as a function (to
do many things as derivative, integrate on specific interval, evaluate at
specific point,...)
To be clear, let's take an example:
a=c(1,3,10,-5,0,0,2, 1, 3, 8,2, -2)
b=density(a)
I would like some transformation of b
f=some_transformation(b) # transformation I don't know
is.function(f) # answer must be "TRUE"
so that I can evaluate the density at any point
f(1.2) # evaluate density at 1.2
compute its derivative
Df=D(body(f), "x") # derivative of f
Df(1.2) # derivative at 1.2
and do other R stuff as if f is a function.
No comments:
Post a Comment