[R] user input in R
rbaer at atsu.edu
Sat Oct 10 18:00:19 CEST 2009
> I'm just learning R (I don't know any other programming languages),
> and I have a question. I am trying to figure out how to ask for user
> input (say, a set of 3 numbers) then put those numbers into an array.
> I've looked around, but I haven't been able to find any answers that I
Astoundingly, finding out how to load my own datasets was one of the hardest
things for me to find information on when I was new to R and I had
considerable programming experience. Part of the problem was that I didn't
yet know exactly what R documentation was available or how to easily access
it. Further, veteran users tend to assume loading datasets is easy, and
much documentation and sample code uses 'generated data'. Thus, sample code
demonstrating 'loading datasets' is a little hard to find when you are
The official recommendation would go something like, "You probably want to
read the Import/Export documentation." You can find this on Windows GUI
under help | manuals | Data Import/Export. Of course you proably also need
to read chapter 7 of An Introduction to R which is also linked under manuals
in the help menu. That said, I offer some beginner cheats you might find
useful below. I particularly recommend the Verzzani Appendix.
Things you could type at the command line to learn more about different ways
to enter data are:
"Beginner cheats Suggestions"
If you want GUI data input (of dataframes), I'd suggest installing and
running the Rcmdr package. It lets you load many types of datasets,
including Excel files. These can be used within Rcmdr or from the command
If you are really new to R, I suggest looking at some of the contributed
documentation to get a feel for how things are done as well as how to load
In particular, look at the appendix in John Verzzani's document to see a
pragmatic description of using scan to input user data. (see Appendix:
Entering Data in R on p. 103 or so).
More information about the R-help