. Advertisement .
..3..
. Advertisement .
..4..
I get the error message:
Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
> predict(model, df$Total, interval="confidence")
Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
Has anyone ever faced this problem? How to troubleshoot the “ error in eval(predvars, data, env) : numeric ‘envir’ arg not of length one” But the problem is appearing when I try to operate the following program:
# source: error in eval(predvars, data, env) : numeric 'envir' arg not of length one
> df = read.table(text = '
+ TRip Distance Duration
+ 1 "#3" 2027.072 081.082
+ 2 "#4" 3476.802 139.072
+ 3 "#5" 4622.174 184.886
+ 4 "#6" 4214.416 168.576
+ 5 "#7" 6553.586 262.143
+ 6 "#8" 7123.162 284.926
+ 7 "#9" 7987.369 319.494', header=TRUE)
>
> model = lm(df$Duration ~ df$Distance)
>
> x = predict(model, df$Distance)
The cause: The predict() function looks for a data frame in the second position but “df$Distance” is simply a vector produced by extracting the second column from the data frames “df” such that you are entering the wrong type of data, this is what causes the function to result in an error message.
Solution: Convert vector “df$Distance” into a data frame so that it will be accepted by the predict() function.
This version distinguishes from the one that produces the error message is that it puts “df$Distance” through the data.frame() function.