To get the partial derivative of a function in R, you can use the D()
function from the Deriv()
package.
The syntax for using D()
is as follows:
main.r26 chars2 lines
Where expression
is the mathematical expression you want to take the partial derivative of, and "variable"
is the variable with respect to which you want to take the derivative. Here is an example:
main.r132 chars10 lines
This will give you the partial derivative of f
with respect to x
.
Note that the syntax for the D()
function is a little different from the standard mathematical notation for partial derivatives. In R, you need to put the function expression and the variable in separate arguments, and you need to enclose the function expression in quotes.
gistlibby LogSnag