Read a typed number (R)

1

Hello everyone, I need to do a barbadinha script in R where I have to read a typed number and give its predecessor (type, if I type 10 the predecessor is 9).

But I have a problem that I do not know how it makes the start ...

print("Digite um numero")
//O QUE VAI AQUI PARA LER O NUMERO DIGITADO
nAntecessor= numero-1
print("O antecessor é:", nAntecessor)

I'm using the R Project program ...

    
asked by anonymous 13.09.2017 / 18:53

1 answer

1

The answer is very simple, just use scan without any argument.

print("Digite um numero")
numero <- scan()
nAntecessor <- numero - 1
cat("O antecessor é: ", nAntecessor, "\n")

Note that I changed the print to cat . Since no was not enough, print only uses one argument. To use it would have to be

print(paste("O antecessor é: ", nAntecessor))
    
23.09.2017 / 21:56