12

 

 

File Input and Output

 

Getting data into and out of files is one of the fundamental necessities of a computing platform. There are many facilities for doing so in both R and MATLAB.

For reading text data from files, R has the functions read.table, scan, and readLines, while MATLAB has load, fgetl, fscanf, textread, textscan, and importdata. Often, more than one of these functions can be used to accomplish a given task. Which one is best is partly personal preference, and may also depend on the type of variable you want to store the data in. The following examples of some common tasks may help to suggest some possible approaches. Note that these commands will all read and write files in the current working directory (see Section 7.1

Get R and MATLAB 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.