Reputation: 11
I'm getting an error in my R program that says:
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
cannot coerce type 'closure' to vector of type 'double'
Here is my code, I can't figure out where it's coming from:
n=900000
plot(density(rt(n,n-1)),xlim=c(-10,5),main="",xlab="")
abline(v=t,col="red")
Upvotes: 1
Views: 5131
Reputation: 213
I resolved a similar problem by converting the "closure" type to numeric type using: as.numeric(t)
Upvotes: 0
Reputation: 33938
The error is referring to you accidentally passing a function name (t
) instead of a numeric as x-coord of your abscissa, as @nrussell said:
abline(v=t,col="red")
I think you meant T
/TRUE
and assumed the v/h-arguments to abline were booleans, but they're not, it needs numeric coords (if it was only a boolean, how would it know where to put the abscissa?):
abline(a = NULL, b = NULL, h = NULL, v = NULL, reg = NULL,
coef = NULL, untf = FALSE, ...)
Arguments:
a, b: the intercept and slope, single values.
h: the y-value(s) for horizontal line(s).
v: the x-value(s) for vertical line(s).
....
Anyway in this case you want to put it at x=0:
abline(v=0, col='red')
Don't forget, R is case-sensitive, so t
is not T
/TRUE
. This ain't Lisp, baby...
Upvotes: 4