How to get a 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
derivg
x = 2
eval(derivg, list(x = 2)) [1] 4