Jim holtman What you need to do is to see that is in 'wektnok' at that point in your program. You should be able to see it with str(wektnok) when the error occurs. You can also add a print statement in the loop to print out the value before it is used with the binary operator.
It would help if you provided 'str' of the various objects you are using, or maybe some reproducible code. Somehow you are creating a non-numeric value in your code; you need to debug it and check all the values before you use. What you need to do is to see that is in 'wektnok' at that point in yourprogram. You should be able to see it with str(wektnok) when the erroroccurs. You can also add a print statement in the loop to print out thevalue before it is used with the binary operator.It would help if you provided 'str' of the various objects you are using, ormaybe some reproducible code.
Warning: Error in.: non-numeric argument to binary operator. Dear All, Please what could be the cause of this error, I created a GUI with shiny. Error in.pointsToMatrix(p1). toRad: non-numeric argument to binary operator. By debopriyo sanyalin Questions & Answers 2 years ago. I am running the below.
Somehow you are creating a non-numeric valuein your code; you need to debug it and check all the values before you usethem. On Sun, May 31, 2009 at 7:05 PM, GrzeĀ¶ wrote:Thanks jholtman!But I'm not sure what and where I should change my code.:(wektn = ndfi,wektnok = wektn!is.na(wektn)If before this line I should change 'wektnok' as numeric? But if I wroteas.numeric(wektnok) it's also not correctand I also don't understand why 'wektnok' is not numeric?-View this message in context:Sent from the R help mailing list archive at [email protected] mailing listPLEASE do read the posting guideand provide commented, minimal, self-contained, reproducible code.-Jim HoltmanCincinnati, OH+1 513 646 9390What is the problem that you are trying to solve? 1. 'a'Error in 1. 'a': non-numeric argument to binary operatorThough the user should have been able to figure this out, perhaps the errormessage could be improved? After all, it is not the fact that the operatoris.binary.
that implies that its argument must be numeric, but that it is.arithmetic. The binary operator%in%, for example, takes non-numericarguments.Suggested replacement error message:non-numeric argument to arithmetic operator-salternative HTML version deletedR-help at r-project.org mailing listPLEASE do read the posting guideand provide commented, minimal, self-contained, reproducible code. Stavros Macrakis Agreed, that's even better, e.g. Error in 1.
'a': character argument not allowed for arithmetic operator. For some reason (does anyone know the rationale?), in the case of factors, you don't get an error, but a more explicit warning and an NA result: 1 NA Warning message: In Ops.factor(2, factor(3)):. not meaningful for factors This seems hazardous, especially since the user has to be sophisticated enough to know about options(warn=2) to get a traceback for this. As for data frames. Error in 1. 'a': non-numeric argument to binary operatorThough the user should have been able to figure this out, perhaps theerrormessage could be improved?
After all, it is not the fact that the operatoris.binary. that implies that its argument must be numeric, but that it is.arithmetic. The binary operator%in%, for example, takes non-numericarguments.Suggested replacement error message:non-numeric argument to arithmetic operator-salternative HTML version [email protected] mailing listPLEASE do read the posting guideand provide commented, minimal, self-contained, reproducible code. Wacek Kusnierczyk i think the error message might be even better, but this would require '. to be even better.
I know some will take it for lamenting: there is an ugly lack of consistency here: 1:2 # 1 2 1:2.5 # 1 2 (coercion double - integer) 1:'2' # 1 2 (corecion character - integer) 1:'a' # Error in 1:'a': NA/NaN argument # In addition: Warning message: # NAs introduced by coercion 1. 2 # 2 1. '2' # Error in 1. '2': non-numeric argument to binary operator 1. '2' # Error in 1.
'a': non-numeric. I think the error message might be even better, but this would require'.
to be even better. Stavros Macrakis I agree that it's inconsistent that 1:'2' - 1:2 # this doesn't seem to be documented in?
Seq 1+ '2' - error 1+factor(2) - NA (with a warning) 1: factor(4) - 1 (uses as.numeric/unclass of factor) But I disagree that the best thing to do here is to have them all coerce to numerics. In scripting languages like Perl which are constantly going back and forth between internal and external representations, it makes some sense to auto-convert numeric strings to numerics and vice versa, but I. Wacek Kusnierczyk i think either approach is correct in the scripting language r, provided the users do not have to navigate between exceptions and errors due to the inconsistent design. I agree that having 1:'2' result in an error might be better than what i suggested above.
I said 'i'd expect a successful computation' wrt. 1. '2' not because i think it is the best r could do, but because r already messes with implicit coercions (as in 1:'2' and 1 + 0i, but not 1.' 2' and sqrt(0i)), and it would be easier to.i'd expect.a successful computation (with a character - numericcoercion of '2' to 2).But I disagree that the best thing to do here is to have them all coerce tonumerics. In scripting languages like Perl which are constantly going backand forth between internal and external representations, it makes some senseto auto-convert numeric strings to numerics and vice versa, but I don'tthink it makes sense in a statistical language.I would rather see them all give errors.i think either approach is correct in the scripting language r, providedthe users do not have to navigate between exceptions and errors due tothe inconsistent design.i agree that having 1:'2' result in an error might be better than what isuggested above. I said 'i'd expect a successful computation' wrt. 1.'
2' not because i think it is the best r could do, but because r alreadymesses with implicit coercions (as in 1:'2' and 1 + 0i, but not 1.' 2'and sqrt(0i)), and it would be easier to learn if you could alwaysexpect a string to be (attempted to be) coerced to numeric in anarithmetic context.vQ. Wacek Kusnierczyk you're right; it actually seems to be a.bug. that 1:'2' or '1':2 'successfully' return.?'
:' says: 'The binary operator ':' has two meanings: for factors 'a:b' is equivalent to 'interaction(a, b)' (but the levels are ordered and labelled differently). For numeric arguments 'from:to' is equivalent to 'seq(from, to)', and generates a sequence from 'from' to 'to' in steps of '1' or '1-'.' But '1' and '2' are neither factors nor numerics, and ':' should have no meaning for them.i'd expect.a successful computation (with a character - numericcoercion of '2' to 2).But I disagree that the best thing to do here is to have them all coerce tonumerics. In scripting languages like Perl which are constantly going backand forth between internal and external representations, it makes some senseto auto-convert numeric strings to numerics and vice versa, but I don'tthink it makes sense in a statistical language.I would rather see them all give errors.you're right; it actually seems to be a.bug. that 1:'2' or '1':2'successfully' return.?' :' says:'The binary operator ':' has two meanings: for factors 'a:b' isequivalent to 'interaction(a, b)' (but the levels are ordered andlabelled differently).
For numeric arguments 'from:to' is equivalent to'seq(from, to)', and generates a sequence from 'from' to 'to' in stepsof '1' or '1-'.' But '1' and '2' are neither factors nor numerics, and ':' should have nomeaning for them.interestingly,0i:1# 0 1'0':1# 0 1i.e., both the complex 0i and the character '0' are successfully (butundocumentedly) coerced to integers, but'0i':1# Error in '0i':1: NA/NaN argument# In addition: Warning message:# NAs introduced by coercionwhile it does not follow from?' :' that the arguments are implicitlycoerced to numerics, it seems a plausible explanation:as.numeric(0i)# 0as.numeric('0')# 0as.numeric('0i')# NAinterestingly,as.complex('0i')# NA?as.complex does not explain what sorts of arguments are coercible tocomplex, beyond 'an object, probably of mode 'complex'. If as.numericcan coerce strings to numerics, why can't as.complex do the same forcomplex numbers?vQ.
Because your question is phrased regarding your error message and not whatever your function is trying to accomplish, I will address the error.- is the 'binary operator' your error is referencing, and either CurrentDay or MA (or both) are non-numeric.A binary operation is a calculation that takes two values (operands) and produces another value. + is one such operator: '1 + 1' takes two operands (1 and 1) and produces another value (2).
Note that the produced value isn't necessarily different from the operands (e.g., 1 + 0 = 1).R only knows how to apply + (and other binary operators, such as -) to numeric arguments: 1 + 11 2 1 + 'one'Error in 1 + 'one': non-numeric argument to binary operatorWhen you see that error message, it means that you are (or the function you're calling is) trying to perform a binary operation with something that isn't a number.EDIT:Your error lies in the use of instead of. Because Day is a list, subsetting with will return a list, not a numeric vector.
, however, returns an object of the class of the item contained in the list: Day class(Day)1 'list' Day + 1Error in Day + 1: non-numeric argument to binary operator Day2 class(Day2)1 'numeric' Day2 + 11 3Transaction, as you've defined it, returns a list of two vectors. Above, Day is a list contain one vector. Day2, however, is simply a vector.