以错误的方式访问df列会导致空向量,“没有不丢失的参数给min/max,返回Inf/-Inf”

时间:2022-01-26 22:52:06

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:

我是研究水质数据的初学者。请原谅我格式化错误。我试图在我的数据集中运行“nls”。运行脚本:

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

警告消息:1:In min(x):对于min没有非缺失参数;返回inf2:在max(x)中:对max没有不遗漏的参数;返回负

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.

数据集没有NAs,并且都是数值。我跑范围(testingQ na。也有范围(testingQ, na)。rm = FALSE)只要尝试一下,它会返回数据集中的最大值和最小值。我不知道还能尝试什么。期待某人的解决方案!谢谢。

1 个解决方案

#1


1  

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

总结你已经解决的问题并在评论中写下:

  • issue had nothing to do with nls or max
  • 问题与nls和max无关
  • issue was due to a bad access to a dataframe column, either bad syntax or else you had shadowed the definitions of Q, GR by defining variables with those names
  • 问题是由于对dataframe列的访问不正确,或者是语法不正确,或者是您通过定义带有这些名称的变量来给Q的定义蒙上阴影
  • this then gave you an empty vector, which causes max to return Inf/-Inf
  • 这就给了你一个空的向量,使得max返回Inf/-Inf
  • solution was to fix the column access, or don't define the offending shadowing variables
  • 解决方案是修复列访问,或者不定义讨厌的阴影变量。

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.

我的建议:总结一下,max和min在R中很痛苦,因为它们不能很好地处理NAs或完全空的输入。所以,要么观察它们的输入向量来检查它们的完整性,要么把它们的输入赋值给一个变量,然后检查它。

#1


1  

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

总结你已经解决的问题并在评论中写下:

  • issue had nothing to do with nls or max
  • 问题与nls和max无关
  • issue was due to a bad access to a dataframe column, either bad syntax or else you had shadowed the definitions of Q, GR by defining variables with those names
  • 问题是由于对dataframe列的访问不正确,或者是语法不正确,或者是您通过定义带有这些名称的变量来给Q的定义蒙上阴影
  • this then gave you an empty vector, which causes max to return Inf/-Inf
  • 这就给了你一个空的向量,使得max返回Inf/-Inf
  • solution was to fix the column access, or don't define the offending shadowing variables
  • 解决方案是修复列访问,或者不定义讨厌的阴影变量。

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.

我的建议:总结一下,max和min在R中很痛苦,因为它们不能很好地处理NAs或完全空的输入。所以,要么观察它们的输入向量来检查它们的完整性,要么把它们的输入赋值给一个变量,然后检查它。