I know that readline()
is used to get user input. But how to use it to get a range of values?
Eg: I need to get 10 random numbers from user and want to do some operations on them. Please help!
PS: I am totally new to R.
I know that readline()
is used to get user input. But how to use it to get a range of values?
Eg: I need to get 10 random numbers from user and want to do some operations on them. Please help!
PS: I am totally new to R.
scan()
lets you enter multiple inputs, separated by a space or a newline and termined by two newlines.
Assigning the result x <- scan()
yields a vector in case of multiple inputs.
This does not ensure that you get exactly ten inputs though.
If you want exactly ten inputs, you could prompt ten times:
x <- numeric(10)
for(i in 1:10){
x[i] <- readLines()
}