How do I get the derivative of the following function?
g <- expression(x^2)
derivg <- D(g, 'x')
derivg
# 2 * x
g1 <- derivg(2)
# Error: could not find function "derivg"
I want to find the derivative at x = 2.
derivg
is a call, not a function. To evaluate it at x = 2
, you can do
eval(derivg, list(x = 2))
[1] 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With