Data Input from Files

You can read data from a file using scan (see p. 102) but read.table is much more user-friendly. The read.table function reads a file in table format and automatically creates a dataframe from it, with cases corresponding to rows (lines) and variables to columns (fields) in the file (see p. 107). Much the simplest way to proceed is always to make your dataframe as a spreadsheet in Excel, and always to save it as a tab-delimited text file. That way you will always use read.table for data input, and you will avoid many of the most irritating problems that people encounter when using other input formats.

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.