SlideShare a Scribd company logo
EXPANDING DATA FRAMES IN R
(ADDING COLUMNS AND ROWS)
Presented by
Ms Subhasheni A
Assistant Professor
Department of Computer Science
Sri Ramakrishna College of Arts & Science
Coimbatore
INTRODUCTION TO DATA FRAME EXPANSION
 Data frames in R are dynamic and can be
modified easily.
 Expansion involves adding new columns or
rows to existing data.
 Useful when combining datasets or appending
new results.
REVIEW - CREATING A DATA FRAME
emp_data <- data.frame(
ID = c(1, 2, 3),
Name = c("John", "Anna", "Peter"),
Salary = c(70000, 80000, 90000))
ADDING A COLUMN USING $ OPERATOR
 Add directly by assigning values to a new
column name:
 emp_data$Department <- c("HR", "Finance", "IT")
 Make sure the new column length matches the
number of rows.
ADDING A COLUMN USING CBIND()
 Bind column-wise:
 emp_data <- cbind(emp_data, Grade)
 cbind() is useful for combining columns from
other vectors/data frames.
ADDING A ROW USING RBIND()
 Create a row as a data frame:
 Example:
new_row <- data.frame(
ID = 4, Name = "Sara", Salary = 85000,
Department = "Admin",
Grade = "B")
emp_data <- rbind(emp_data, new_row)
 Column names and data types must match exactly.
COMMON ERRORS WHEN EXPANDING DATA FRAMES
 Mismatch in number of columns.
 Inconsistent data types (e.g., character vs
factor).
 Misspelled or unmatched column names.
CONCLUSION
 Use $ and cbind() to add columns.
 Use rbind() to add rows.
 Ensure data compatibility to avoid binding
errors.
THANK YOU!

More Related Content

PPTX
Understanding Data Frames in R Programming
subhashenia
 
PPTX
3. R- list and data frame
krishna singh
 
PDF
3 Data Structure in R
Dr Nisha Arora
 
PPTX
R environment
Daniele Ronzani
 
PDF
Day 2b i/o.pptx
Adrien Melquiond
 
PPTX
R Functions in Dataframe.pptx
Ramakrishna Reddy Bijjam
 
PPTX
data frames.pptx
RacksaviR
 
PPTX
DataStructures.pptx
Thanuj Pothula
 
Understanding Data Frames in R Programming
subhashenia
 
3. R- list and data frame
krishna singh
 
3 Data Structure in R
Dr Nisha Arora
 
R environment
Daniele Ronzani
 
Day 2b i/o.pptx
Adrien Melquiond
 
R Functions in Dataframe.pptx
Ramakrishna Reddy Bijjam
 
data frames.pptx
RacksaviR
 
DataStructures.pptx
Thanuj Pothula
 

Similar to How to Add Columns and Rows in an R Data Frame (20)

PPTX
R programming
Pramodkumar Jha
 
PDF
Machine Learning in R
Alexandros Karatzoglou
 
PPTX
Factors.pptx
Ramakrishna Reddy Bijjam
 
PDF
R_CheatSheet.pdf
MariappanR3
 
PDF
R learning by examples
Michelle Darling
 
PPTX
Introduction to R _IMPORTANT FOR DATA ANALYTICS
HaritikaChhatwal1
 
PDF
Ggplot2 work
ARUN DN
 
PPTX
Big Data Mining in Indian Economic Survey 2017
Parth Khare
 
PPTX
R Programming and Lab - Unit III pptxs
SARAVANA KUMAR SS
 
PDF
Introduction to R
vpletap
 
PPTX
Get started with R lang
senthil0809
 
PDF
20130215 Reading data into R
Kazuki Yoshida
 
PPTX
R교육1
Kangwook Lee
 
DOCX
Introduction to r
Golden Julie Jesus
 
PPTX
Introduction to R programming Language.pptx
kemetex
 
PPTX
Data Management in R
Sankhya_Analytics
 
PPTX
Data Handling in R language basic concepts.pptx
gameyug28
 
PPTX
Data Exploration in R.pptx
Ramakrishna Reddy Bijjam
 
PPTX
A quick introduction to R
Angshuman Saha
 
PDF
Data Manipulation Using R (& dplyr)
Ram Narasimhan
 
R programming
Pramodkumar Jha
 
Machine Learning in R
Alexandros Karatzoglou
 
R_CheatSheet.pdf
MariappanR3
 
R learning by examples
Michelle Darling
 
Introduction to R _IMPORTANT FOR DATA ANALYTICS
HaritikaChhatwal1
 
Ggplot2 work
ARUN DN
 
Big Data Mining in Indian Economic Survey 2017
Parth Khare
 
R Programming and Lab - Unit III pptxs
SARAVANA KUMAR SS
 
Introduction to R
vpletap
 
Get started with R lang
senthil0809
 
20130215 Reading data into R
Kazuki Yoshida
 
R교육1
Kangwook Lee
 
Introduction to r
Golden Julie Jesus
 
Introduction to R programming Language.pptx
kemetex
 
Data Management in R
Sankhya_Analytics
 
Data Handling in R language basic concepts.pptx
gameyug28
 
Data Exploration in R.pptx
Ramakrishna Reddy Bijjam
 
A quick introduction to R
Angshuman Saha
 
Data Manipulation Using R (& dplyr)
Ram Narasimhan
 
Ad

More from subhashenia (17)

PPTX
How to Make Pie Charts in R Programming language
subhashenia
 
PPTX
Data Collection Strategies for Better Insights#DataCollection
subhashenia
 
PPTX
What Is Data Integration and Transformation?
subhashenia
 
PPTX
Powerful Uses of Data Analytics You Should Know
subhashenia
 
PPTX
R Data Types: A Beginner’s Guide to Data in R
subhashenia
 
PPTX
Understanding Operators in R Programming
subhashenia
 
PPTX
Introduction to Data Analytics and Its Importance
subhashenia
 
PPTX
Key Features and Benefits of Using DHTML
subhashenia
 
PPTX
Components of DHTML for Dynamic Web Pages
subhashenia
 
PPTX
HTML Table Layout: Structure, Tags, and Features
subhashenia
 
PPTX
Understanding the Core Concepts of Hypertext
subhashenia
 
PPTX
Introduction to Web Publishing for Beginners
subhashenia
 
PPTX
Cyber Security Basics: Stay Safe in the Digital World
subhashenia
 
PPTX
Introduction to Web Communication Protocols
subhashenia
 
PPTX
Introduction to Distributed Database with Concurrency control in Relation Dat...
subhashenia
 
PPTX
Introduction about Microsoft Office 365 and its usage
subhashenia
 
PPTX
Overall system structure in Relational Database Management System
subhashenia
 
How to Make Pie Charts in R Programming language
subhashenia
 
Data Collection Strategies for Better Insights#DataCollection
subhashenia
 
What Is Data Integration and Transformation?
subhashenia
 
Powerful Uses of Data Analytics You Should Know
subhashenia
 
R Data Types: A Beginner’s Guide to Data in R
subhashenia
 
Understanding Operators in R Programming
subhashenia
 
Introduction to Data Analytics and Its Importance
subhashenia
 
Key Features and Benefits of Using DHTML
subhashenia
 
Components of DHTML for Dynamic Web Pages
subhashenia
 
HTML Table Layout: Structure, Tags, and Features
subhashenia
 
Understanding the Core Concepts of Hypertext
subhashenia
 
Introduction to Web Publishing for Beginners
subhashenia
 
Cyber Security Basics: Stay Safe in the Digital World
subhashenia
 
Introduction to Web Communication Protocols
subhashenia
 
Introduction to Distributed Database with Concurrency control in Relation Dat...
subhashenia
 
Introduction about Microsoft Office 365 and its usage
subhashenia
 
Overall system structure in Relational Database Management System
subhashenia
 
Ad

Recently uploaded (20)

PPTX
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
PPTX
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
PPTX
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
PDF
CH2-MODEL-SETUP-v2017.1-JC-APR27-2017.pdf
jcc00023con
 
PDF
Company Profile 2023 PT. ZEKON INDONESIA.pdf
hendranofriadi26
 
PPTX
Complete_STATA_Introduction_Beginner.pptx
mbayekebe
 
PDF
345_IT infrastructure for business management.pdf
LEANHTRAN4
 
PPTX
Analysis of Employee_Attrition_Presentation.pptx
AdawuRedeemer
 
PDF
Key_Statistical_Techniques_in_Analytics_by_CA_Suvidha_Chaplot (1).pdf
CA Suvidha Chaplot
 
PPTX
lecture 13 mind test academy it skills.pptx
ggesjmrasoolpark
 
PPTX
Decoding Physical Presence: Unlocking Business Intelligence with Wi-Fi Analytics
meghahiremath253
 
PPTX
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
PDF
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
PPTX
The whitetiger novel review for collegeassignment.pptx
DhruvPatel754154
 
PPTX
International-health-agency and it's work.pptx
shreehareeshgs
 
PDF
Technical Writing Module-I Complete Notes.pdf
VedprakashArya13
 
PDF
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
PDF
oop_java (1) of ice or cse or eee ic.pdf
sabiquntoufiqlabonno
 
PDF
Linux OS guide to know, operate. Linux Filesystem, command, users and system
Kiran Maharjan
 
PDF
Chad Readey - An Independent Thinker
Chad Readey
 
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
CH2-MODEL-SETUP-v2017.1-JC-APR27-2017.pdf
jcc00023con
 
Company Profile 2023 PT. ZEKON INDONESIA.pdf
hendranofriadi26
 
Complete_STATA_Introduction_Beginner.pptx
mbayekebe
 
345_IT infrastructure for business management.pdf
LEANHTRAN4
 
Analysis of Employee_Attrition_Presentation.pptx
AdawuRedeemer
 
Key_Statistical_Techniques_in_Analytics_by_CA_Suvidha_Chaplot (1).pdf
CA Suvidha Chaplot
 
lecture 13 mind test academy it skills.pptx
ggesjmrasoolpark
 
Decoding Physical Presence: Unlocking Business Intelligence with Wi-Fi Analytics
meghahiremath253
 
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
The whitetiger novel review for collegeassignment.pptx
DhruvPatel754154
 
International-health-agency and it's work.pptx
shreehareeshgs
 
Technical Writing Module-I Complete Notes.pdf
VedprakashArya13
 
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
oop_java (1) of ice or cse or eee ic.pdf
sabiquntoufiqlabonno
 
Linux OS guide to know, operate. Linux Filesystem, command, users and system
Kiran Maharjan
 
Chad Readey - An Independent Thinker
Chad Readey
 

How to Add Columns and Rows in an R Data Frame

  • 1. EXPANDING DATA FRAMES IN R (ADDING COLUMNS AND ROWS) Presented by Ms Subhasheni A Assistant Professor Department of Computer Science Sri Ramakrishna College of Arts & Science Coimbatore
  • 2. INTRODUCTION TO DATA FRAME EXPANSION  Data frames in R are dynamic and can be modified easily.  Expansion involves adding new columns or rows to existing data.  Useful when combining datasets or appending new results.
  • 3. REVIEW - CREATING A DATA FRAME emp_data <- data.frame( ID = c(1, 2, 3), Name = c("John", "Anna", "Peter"), Salary = c(70000, 80000, 90000))
  • 4. ADDING A COLUMN USING $ OPERATOR  Add directly by assigning values to a new column name:  emp_data$Department <- c("HR", "Finance", "IT")  Make sure the new column length matches the number of rows.
  • 5. ADDING A COLUMN USING CBIND()  Bind column-wise:  emp_data <- cbind(emp_data, Grade)  cbind() is useful for combining columns from other vectors/data frames.
  • 6. ADDING A ROW USING RBIND()  Create a row as a data frame:  Example: new_row <- data.frame( ID = 4, Name = "Sara", Salary = 85000, Department = "Admin", Grade = "B") emp_data <- rbind(emp_data, new_row)  Column names and data types must match exactly.
  • 7. COMMON ERRORS WHEN EXPANDING DATA FRAMES  Mismatch in number of columns.  Inconsistent data types (e.g., character vs factor).  Misspelled or unmatched column names.
  • 8. CONCLUSION  Use $ and cbind() to add columns.  Use rbind() to add rows.  Ensure data compatibility to avoid binding errors.