rinvalid-argument

Accessing df columns the wrong way causes empty vector, "no non-missing arguments to min/max, returning Inf/-Inf"


I am a beginner on R, working on water quality data. PLease excuse my formatting mistakes. I am trying to run "nls" on my dataset. Running the script:

testingQModel<-nls(GR ~ GRm * (1-Kq/Q), data = testingQ, start = list(Kq = min(testingQ$Q), GRm = max(testingQ$GR)))

I get the following error:

Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf

The dataset does not have NAs and is all numeric. I ran range(testingQ, na.rm = TRUE) also with range(testingQ, na.rm = FALSE) just to give it a try either way and it returned maximum and minimum values in dataset all right. I am not sure what else to try. Look forward to a solution from someone! Thanks.


Solution

  • Summarizing what you already seem to have solved and written in the comments:

    My tip: summary, max and min are a pain in R since they don't handle either NAs or completely empty inputs well. So always either eyeball their input vector to double-check for sanity, or else assign their input to a variable and inspect that.