[R] Reading Data

Duncan Murdoch dmurdoch at pair.com
Fri Mar 19 18:25:10 CET 2004


On Fri, 19 Mar 2004 11:47:10 -0500, "Kissell, Robert [EQRE]"
<robert.kissell at citigroup.com> wrote :

>Hi,
>
>Quick question on reading data.
>
>I am running simulations but want to allow the user the option to define the number of simulations. How can I have R read-in user data entered from the keyboard? Is there a difference for reading in numeric and character data?
>
>For example, I am trying to write the following in R:
>
>Enter Number of Iterations?
><<<the user then enters a number say Y >>>
>
>X <- Y       # i then want to read that number into X

You want readline.  It returns a single element character vector;
you'll need to convert it to a number.  For example

> Y <- as.numeric(readline('Enter number of iterations:'))
Enter number of iterations:34
> Y
[1] 34




More information about the R-help mailing list