SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Import & Export Data
in R
Rupak Roy
As mentioned earlier, R takes the lead in data analysis by
supporting various types of formats from SAS , SPSS , SQL, Excel,
CSV, Twitter API and so on.
With the given data formats R have various methods to read
those into R .
Some of the commonly used methods of reading data in R
1. scan
2. read.table
3. read.delim
4. read.csv
5. read.csv.sql
6. fread
R Import Functions
Rupak Roy
1. scan(): reads data into a vector or list from the console or a file .
> s <- scan (“testing.csv”, what = “ ” , sep=“ ,” , skip =1)
where,
what = “ ”( if we don’t use this it will through error, since default is numeric)
sep = “,” ( represents the delimiter that separates the line )
skip = 1 (skips the first row )
for more info we can always use > ?scan
2. read.table(): reads a file in table format and creates a data frame from it.
> t <- read.table( file.choose() , header = TRUE, sep = “,” , StringAsFactors =F )
StringAsFactors = F i.e. FALSE refers load the string variables without converting
them into factors .
> str(t) #observe the structure before and after StringAsFactors = F )
#to read a tab delimited file
> t <- read.table (file.chose(), header = TRUE, sep=“t”)
R Import Functions
3. read.delim(): useful to read delimited file like tab ( t) separate file and
comma ( , ) separated file. It is just a wrapper function of read.table()
> r <- read.delim(file.choose(),sep = ",", header = TRUE)
4. read.csv(): the most commonly used function to read a csv file. Again it
is a wrapper function of read.table()
> c <- read.csv(file.choose(),sep=“;”, header= TRUE, dec= “.”)
Where,
dec = the character used in the file for decimal points.
Note: we can use “ ? ” like ?read.delim, ?read.csv to know more about the
parameters and the features of the function.
R Import Functions
Rupak Roy
R Import Functions
5. read.lines(): Reads the entire row or all text lines from a connection as line.
> readLines(con = stdin(), n = -1L, ok = TRUE, warn = TRUE, encoding = "unknown",
skipNul = FALSE)
Where,
con= refers connection to a object, for example a character string file.
n= The (maximal) number of lines to read. Negative values indicate that one should
read up to the end of input on the connection.
Ok= logical parameter to reach the end of the connection before n > 0 lines are
read? If not, an error will be generated.
Warn= logical parameter that that warns if a text file is missing or if there are
embedded nulls in the file.
Encoding= encoding to be assumed for input strings. By default standard UTF=8 is
assumed for input strings.
skipNul= logical parameter indicating should nulls be skipped or not.
R Import Functions
• R treats/identifies missing values in different ways:
For numeric variables – empty spaces
For character variables – should have NA hard coded for empty spaces.
R also identifies formats like NaN, Inf, -Inf as empty or missing values.
With the scalability features of R if the data have different format other than those
R also provides options to refer a missing or empty values using na.string(“ ”)
Rupak Roy
R Import Functions
 Special parameters:
Strip.white = TRUE
To identify extra white spaces present in character strings.
Blank.lines.skip = FALSE
Helps to ignore the blank lines
FILL = TRUE
To identify rows if unequal length
For comments use comment.char = “ ” we can always use ?read.csv,
?read.table to get the full list of parameters available for each function.
Next:
How to export our analysis or any data from the R
objects into a csv or a delimited value files
Import & Export Data
in R
Rupak Roy

More Related Content

PDF
Data Types and Structures in R
PDF
R Programming: Importing Data In R
PDF
R Programming: Introduction To R Packages
PPTX
Python Seaborn Data Visualization
PDF
An Introduction to Data Mining with R
PDF
R data-import, data-export
 
PPTX
Introduction to numpy Session 1
PPTX
Decision tree induction \ Decision Tree Algorithm with Example| Data science
Data Types and Structures in R
R Programming: Importing Data In R
R Programming: Introduction To R Packages
Python Seaborn Data Visualization
An Introduction to Data Mining with R
R data-import, data-export
 
Introduction to numpy Session 1
Decision tree induction \ Decision Tree Algorithm with Example| Data science

What's hot (20)

PDF
All pairs shortest path algorithm
PPT
3.1 clustering
PPTX
Machine learning with scikitlearn
PPT
1.8 discretization
PPTX
Data visualization using R
PDF
Data tidying with tidyr meetup
PPTX
Ensemble methods
PPTX
Modeling with Recurrence Relations
PPTX
Density based clustering
PPTX
Unit 1 - R Programming (Part 2).pptx
PPTX
Introduction to pandas
PPTX
Back patching
PPTX
Maximal and minimal elements of poset.pptx
PPTX
recurrence relations
PPTX
Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
PPTX
3. R- list and data frame
PPT
Data Structures and Algorithm Analysis
PPTX
Connectivity of graphs
PPT
PPTX
Multidimensional schema of data warehouse
All pairs shortest path algorithm
3.1 clustering
Machine learning with scikitlearn
1.8 discretization
Data visualization using R
Data tidying with tidyr meetup
Ensemble methods
Modeling with Recurrence Relations
Density based clustering
Unit 1 - R Programming (Part 2).pptx
Introduction to pandas
Back patching
Maximal and minimal elements of poset.pptx
recurrence relations
Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
3. R- list and data frame
Data Structures and Algorithm Analysis
Connectivity of graphs
Multidimensional schema of data warehouse
Ad

Similar to Import Data using R (20)

PPTX
BINARY files CSV files JSON files with example.pptx
PPTX
PDF
Import and Export Big Data using R Studio
PPTX
Aggregate.pptx
PDF
CSV Files-1.pdf
PPTX
Data Handling in R language basic concepts.pptx
PDF
R Traning-Session-I 21-23 May 2025 Updated Alpha.pdf
PDF
Export Data using R Studio
PPTX
Reading_csv.pptx
DOCX
Data export in matlab alvian zainuddin
PDF
The Pandas Chapter 5(Important Questions).pdf
PDF
Python - Lecture 11
PPTX
Lecture 3 intro2data
PPTX
Data Management in Python
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
BINARY files CSV files JSON files with example.pptx
Import and Export Big Data using R Studio
Aggregate.pptx
CSV Files-1.pdf
Data Handling in R language basic concepts.pptx
R Traning-Session-I 21-23 May 2025 Updated Alpha.pdf
Export Data using R Studio
Reading_csv.pptx
Data export in matlab alvian zainuddin
The Pandas Chapter 5(Important Questions).pdf
Python - Lecture 11
Lecture 3 intro2data
Data Management in Python
Python basics
Python basics
Python basics
Python basics
Python basics
Python basics
Ad

More from Rupak Roy (20)

PDF
Hierarchical Clustering - Text Mining/NLP
PDF
Clustering K means and Hierarchical - NLP
PDF
Network Analysis - NLP
PDF
Topic Modeling - NLP
PDF
Sentiment Analysis Practical Steps
PDF
NLP - Sentiment Analysis
PDF
Text Mining using Regular Expressions
PDF
Introduction to Text Mining
PDF
Apache Hbase Architecture
PDF
Introduction to Hbase
PDF
Apache Hive Table Partition and HQL
PDF
Installing Apache Hive, internal and external table, import-export
PDF
Introductive to Hive
PDF
Scoop Job, import and export to RDBMS
PDF
Apache Scoop - Import with Append mode and Last Modified mode
PDF
Introduction to scoop and its functions
PDF
Introduction to Flume
PDF
Apache Pig Relational Operators - II
PDF
Passing Parameters using File and Command Line
PDF
Apache PIG Relational Operations
Hierarchical Clustering - Text Mining/NLP
Clustering K means and Hierarchical - NLP
Network Analysis - NLP
Topic Modeling - NLP
Sentiment Analysis Practical Steps
NLP - Sentiment Analysis
Text Mining using Regular Expressions
Introduction to Text Mining
Apache Hbase Architecture
Introduction to Hbase
Apache Hive Table Partition and HQL
Installing Apache Hive, internal and external table, import-export
Introductive to Hive
Scoop Job, import and export to RDBMS
Apache Scoop - Import with Append mode and Last Modified mode
Introduction to scoop and its functions
Introduction to Flume
Apache Pig Relational Operators - II
Passing Parameters using File and Command Line
Apache PIG Relational Operations

Recently uploaded (20)

PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
Computer network topology notes for revision
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PPTX
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
PPT
Reliability_Chapter_ presentation 1221.5784
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PDF
Lecture1 pattern recognition............
PDF
Foundation of Data Science unit number two notes
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
Business Ppt On Nestle.pptx huunnnhhgfvu
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Data_Analytics_and_PowerBI_Presentation.pptx
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
.pdf is not working space design for the following data for the following dat...
Computer network topology notes for revision
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
05. PRACTICAL GUIDE TO MICROSOFT EXCEL.pptx
Reliability_Chapter_ presentation 1221.5784
IBA_Chapter_11_Slides_Final_Accessible.pptx
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Lecture1 pattern recognition............
Foundation of Data Science unit number two notes
Clinical guidelines as a resource for EBP(1).pdf
oil_refinery_comprehensive_20250804084928 (1).pptx

Import Data using R

  • 1. Import & Export Data in R Rupak Roy
  • 2. As mentioned earlier, R takes the lead in data analysis by supporting various types of formats from SAS , SPSS , SQL, Excel, CSV, Twitter API and so on. With the given data formats R have various methods to read those into R . Some of the commonly used methods of reading data in R 1. scan 2. read.table 3. read.delim 4. read.csv 5. read.csv.sql 6. fread R Import Functions Rupak Roy
  • 3. 1. scan(): reads data into a vector or list from the console or a file . > s <- scan (“testing.csv”, what = “ ” , sep=“ ,” , skip =1) where, what = “ ”( if we don’t use this it will through error, since default is numeric) sep = “,” ( represents the delimiter that separates the line ) skip = 1 (skips the first row ) for more info we can always use > ?scan 2. read.table(): reads a file in table format and creates a data frame from it. > t <- read.table( file.choose() , header = TRUE, sep = “,” , StringAsFactors =F ) StringAsFactors = F i.e. FALSE refers load the string variables without converting them into factors . > str(t) #observe the structure before and after StringAsFactors = F ) #to read a tab delimited file > t <- read.table (file.chose(), header = TRUE, sep=“t”) R Import Functions
  • 4. 3. read.delim(): useful to read delimited file like tab ( t) separate file and comma ( , ) separated file. It is just a wrapper function of read.table() > r <- read.delim(file.choose(),sep = ",", header = TRUE) 4. read.csv(): the most commonly used function to read a csv file. Again it is a wrapper function of read.table() > c <- read.csv(file.choose(),sep=“;”, header= TRUE, dec= “.”) Where, dec = the character used in the file for decimal points. Note: we can use “ ? ” like ?read.delim, ?read.csv to know more about the parameters and the features of the function. R Import Functions Rupak Roy
  • 5. R Import Functions 5. read.lines(): Reads the entire row or all text lines from a connection as line. > readLines(con = stdin(), n = -1L, ok = TRUE, warn = TRUE, encoding = "unknown", skipNul = FALSE) Where, con= refers connection to a object, for example a character string file. n= The (maximal) number of lines to read. Negative values indicate that one should read up to the end of input on the connection. Ok= logical parameter to reach the end of the connection before n > 0 lines are read? If not, an error will be generated. Warn= logical parameter that that warns if a text file is missing or if there are embedded nulls in the file. Encoding= encoding to be assumed for input strings. By default standard UTF=8 is assumed for input strings. skipNul= logical parameter indicating should nulls be skipped or not.
  • 6. R Import Functions • R treats/identifies missing values in different ways: For numeric variables – empty spaces For character variables – should have NA hard coded for empty spaces. R also identifies formats like NaN, Inf, -Inf as empty or missing values. With the scalability features of R if the data have different format other than those R also provides options to refer a missing or empty values using na.string(“ ”) Rupak Roy
  • 7. R Import Functions  Special parameters: Strip.white = TRUE To identify extra white spaces present in character strings. Blank.lines.skip = FALSE Helps to ignore the blank lines FILL = TRUE To identify rows if unequal length For comments use comment.char = “ ” we can always use ?read.csv, ?read.table to get the full list of parameters available for each function.
  • 8. Next: How to export our analysis or any data from the R objects into a csv or a delimited value files Import & Export Data in R Rupak Roy