How to resolve R error : non-numeric argument to binary operator?


#1

I have just started learning R from scratch so i m getting trouble in execution of following code in RStudio. Please help…

a<-readline("enter any number ")
b<-a+4
b


#2

@as_tech

Try this -
a<-readline("enter any number ")
b<- as.numeric(a)+4
b

Regards,
Aayush


#3

@aayushmnit

Yes, it worked!!!:slight_smile:
Thank you so much…

But will you please explain me the use of as.numeric() here??

Thank you.


#4

@as_tech,

Yeah so readline function read your input as a character type so as.numeric() just convert your input in a numeric form so that it could be summed up with other numbers.


#5

@aayushmnit
Thank u for the explanation…:slight_smile:


#6

how to ask here?