Reading a Tab-Delimited(txt) File in R Programming Language

Method 1: Using read.delim() Function

The function has two parameters: 

  • file.choose(): It opens a menu to choose a csv file from the desktop.
  • header: It is to indicate whether the first row of the dataset is a variable name or not. Apply T/True if the variable name is present else put F/False.

Example: 

R




# import and store the dataset in data3
data3 <- read.delim(file.choose(), header=T)
 
# display the data
data3


Output: 

Importing Data in R Script

Method 2: Using read.table() Function

This function specifies how the dataset is separated, in this case we take sep=”\t” as the argument.

Example: 

R




# import and store the dataset in data4
data4 <- read.table(file.choose(), header=T, sep="\t")
 
# display the data
data4


Output: 

Importing Data in R Script

Importing Data in R Script

We can read external datasets and operate with them in our R environment by importing data into an R script. R offers a number of functions for importing data from various file formats.

In this article, we are going to see how to Import data in R Programming Language.

Similar Reads

Importing Data in R

First, let’s consider a data set that we can use for the demonstration. For this demonstration, we will use two examples of a single dataset, one in .csv form and another .txt...

Reading a Comma-Separated Value(CSV) File

Method 1: Using read.csv() Function Read CSV Files into R...

Reading a Tab-Delimited(txt) File in R Programming Language

...

Using R-Studio

...

Contact Us