My chunk code is this:
rm(list=ls())
f <- function(x) sqrt(2/pi)*exp(x-x^2/2)
max(f(x))
When I run it into the console I have zero problems and the output is 1.315489 (even if I didn’t define the ‘x’ previously).
But when I try to knit it in R Markdown I have this error:
Error:
! object 'x' not found
Backtrace:
1. global f(x)
Execution halted
How can I calculate the maximum of f?
New contributor
F F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.