Skip to content
Related Articles
Open in App
Not now

Related Articles

Reading contents of a Text File in R Programming – read.table() Function

Improve Article
Save Article
  • Last Updated : 19 Jun, 2020
Improve Article
Save Article

read.table() function in R Language is used to read data from a text file. It returns the data in the form of a table.

read.table(filename, header = FALSE, sep = “”)

header: represents if the file contains header row or not
sep: represents the delimiter value used in file

Example 1: Reading data from same directory

# R program to read a text file
# Get content into a data frame 
data <- read.table("TextFileExample.txt",  
                    header = FALSE, sep = " "
# Printing content of Text File 


   V1 V2 V3
1 100  A  a
2 200  B  b
3 300  C  c
4 400  D  d
5 500  E  e
6 600  F  f

Example 2: Reading data from different directory

# R program to read a text file
# Reading data from another directory 
x<-read.table("D://Data//myfile.txt", header = FALSE) 
# print x 


   V1 V2 V3
1 100 a1 b1
2 200 a2 b2
3 300 a3 b3
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!