Reading data from files

  Large data objects will usually be read as values from external files rather than entered during an . session at the keyboard. . input facilities are simple and their requirements are fairly strict and even rather inflexible. There is a clear presumption by the designers of . that you will be able to modify your input files using other tools, such file editors or perl[*] fit in with the requirements of .. Generally this is very simple.

There is, however, a function make.fields() that can be used to convert a file with fixed width, non separated, input fields into a file with separated fields. There is also a facility count.fields() that will count the number of fields on each line of such a file. Occasionally for very simple conversion and checking problems these may be adequate to the task, but in most cases it is better to do the preliminary spade work before the . session begins.

If variables are to be held mainly in data frames, as we strongly suggest, they should be, an entire data frame can be read directly with the read.table() function. There is also a more primitive input function, scan(), that can be called directly.



 

Jeff Banfield
2/13/1998