How to allow multiple inputs from user using R?

Posted by Juan on Stack Overflow See other posts from Stack Overflow or by Juan
Published on 2010-03-29T18:16:46Z Indexed on 2010/03/29 18:23 UTC
Read the original article Hit count: 323

Filed under:
|
|

For example, if I need that the user specifies the number of rows and columns of a matrix:

PROMPT: Number of rows?:

USER INPUT: [a number]

I need that R 'waits' for the input. Then save [a number] into a variable v1. Next,

PROMPT: Number of columns?:

USER INPUT: [another number]

Also save [another number] into a variable v2. At the end, I will have two variables (v1, v2) that will be used in the rest of the code.

"readline" only works for one input at a time. I can't run the two lines together

v1 <- readline("Number of rows?: ")
v2 <- readline("Number of columns?: ")

Any ideas or suggestions?

Thank you in advance

© Stack Overflow or respective owner

Related posts about r

    Related posts about user-input