[R] Question about error of "non-numeric argument to binary operator"

David Winsemius dwinsemius at comcast.net
Thu May 5 16:25:15 CEST 2011


On May 5, 2011, at 1:31 AM, Maximo Polanco wrote:

> I have been trying to do a nls model and gives me the error of a  
> nonnumeric
> argument
>
> This is my data set
> 	
> TT
>
> FFT
>
> V
>
> C
>
> table(file="c:/tt2.txt",header=T)
>
>> fit.model <- nls(TT~60*(1+alpha*(v/c)^beta),data=tt2,  
>> start=list(alpha=1,
> beta=3, v=1000))
>
> Error in v/c : non-numeric argument to binary operator

You have (perhaps) defined a column name of "C" and then attempted to  
reference it with "c". Since `c` is a (rather fundamental) function in  
R, the interpreter has no problem accessing `c` but trying to take   
the ratio of a scalar to a function fails.

You can try changing "c" to "C" above and it may "work", but in the  
future, please heed the issues raised at the bottom of this trimmed  
message!

(It would be much better to not use either "C" or "c" for object names  
since they are both function names.)

?"C"
C {stats}
R Documentation
Sets Contrasts for a FactorDescription
Sets the "contrasts" attribute for the factor.

Usage
C(object, contr, how.many, ...)


>
>> is.numeric(tt2)
>
> [1] FALSE
>
>> is.character(tt2)
>
> [1] FALSE
>
>> as.numeric(tt2)
>
> Error: (list) object cannot be coerced to type 'double'
>
>>
>
> This is my data set
> 	
> TT
>
> FFT
>
> V
>
> C
>
>
> 1
>
> 70.475
>
> 60
snipped long ... incorrectly formatted data due to failing to post in  
plain text.
>
>
>
>
> 	[[alternative HTML version deleted]]
***************************
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
###########################

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list