How to Sort and Order Data in R
How to Use the apply() Function to Summarize Arrays in R
How to Analyze Data Variances in Models with R

How to Use read.table() to Import Tabular Data in R

The functions read.csv(), read.csv2(), and read.delim() are special cases of the multipurpose read.table() function in R that can deal with a wide variety of data file formats. The read.table() function has a number of arguments that give you fine control over the specification of the text file you want to import. Here are some of these arguments:

  • header: If the file contains column names in the first row, specify TRUE.

  • sep: The data separator (for example, sep="," for CSV files or sep="\t" for tab-separated files).

  • quote: By default, strings are enclosed in double quotation marks ("). If the text file uses single quotation marks, you can specify this as the argument to quote (for example, quote="'", a single quote embedded between double quotes).

  • nrows: If you want to read only a certain number of rows of a file, you can specify this by providing an integer number.

  • skip: Allows you to ignore a certain number of lines before starting to read the rest of the file.

  • stringsAsFactors: If TRUE, it converts strings to factors. It’s FALSE by default.

You can access the built-in help by typing ?read.table into your console.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Plot Summarized Data in a ggplot2 in R
How to Add Titles and Axis Labels to a Plot in R
How to Name the Values in Your Vectors in R
How to Debug Your Code in R
How to Test Data Normality Graphically in R