curve in R:'expr' must be a function, or a call or an expression containing 'x'
plot, r
Solution
You can try this:
rho <- function(x, k = 19000) ifelse(abs(x) <= k, x^2, (2 * k * abs(x)) - k^2)
plot(farm ~ land, data = farmland)
curve(rho, from = -10, to = 10, col = "blue", add = TRUE)
Note that i added some space to your code, it's much easier to read. Also, the `add` parameter takes a logical value (TRUE or FALSE), not a character vector ("TRUE" will probably evaluate to TRUE, but never count on this).
Another option is to use `lines`:
plot(farm ~ land, data = farmland)
x = seq(-10, 10, by = 0.01)
lines(x, rho(x, k = 19000), col = 'blue')
Problem
I receive error drawing curve: ``` rho<-function(t,k) ifelse(abs(t)<=k,t^2,(2*k*abs(t))-k^2) plot(farm~land,data=farmland) curve(rho(k=19000),xlim=c(-10,10),col="blue", add="TRUE") Error in curve(rho(k = 19000), xlim = c(-10, 10), col = "blue", add = "TRUE") : 'expr' must be a function, or a call or an expression containing 'x' ``` How should I fix it?