vishu iyer
vishu iyer

Reputation: 1

Hi am a new R learner.. wrote below two identical code on editior, 2nd one runs fine, while first one has error.. what is wrong with 1st one

1st One

Not run there is an error

repeat{
sc=scan(nmax=1)
if (sc>9) {break} else{
b=switch(sc,"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE")
cat(“\n The Number Entered is “, sc ,” In Alpha it is  “, b,”\n”) } }

the Error is Error: unexpected input in: "b=switch(sc,"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE") cat(“"

2nd One This one runs ok

repeat{
sc=scan(nmax=1)
if (sc>9) {break} else{
b=switch(sc,"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE")
cat("\n The Entered Number is ", sc ," In Alpha it is ", b,"\n") } }

1: 4 Read 1 item The Entered Number is 4 In Alpha it is FOUR

Upvotes: 0

Views: 36

Answers (1)

Alex Skorokhod
Alex Skorokhod

Reputation: 540

“ is not allowed in R as a parentheses.

In the first piece of code you are using “ instead of ".

“ may appear if you copy your code into MS Word first and then into .R file. To securely copy the code pls use Notepad (Notepad++ or IDE) so it preserves " symbol as is and does not transform it into “.

Upvotes: 0

Related Questions