- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add rows in an R data frame?
To add rows in an R data frame, we can follow the below steps −
First of all, create a data frame.
Then, use rbind function and the vectors that will be added as rows to the data frame.
Example
Create the data frame
Let’s create a data frame as shown below −
x<-rpois(25,5) y<-rpois(25,2) df<-data.frame(x,y) df
Output
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
x y 1 9 3 2 4 1 3 5 0 4 8 1 5 5 2 6 6 3 7 7 2 8 3 4 9 5 1 10 2 2 11 5 2 12 2 2 13 8 2 14 12 4 15 7 4 16 3 2 17 4 0 18 8 2 19 6 1 20 2 4 21 3 1 22 4 1 23 4 1 24 4 3 25 2 2
Add rows in the data frame
Using rbind function and the vectors to add rows in the data frame as shown below −
x<-rpois(25,5) y<-rpois(25,2) df<-data.frame(x,y) df<-rbind(df,c(5,5),c(2,1),c(0,1),c(5,4),c(3,6)) df
Output
x y 1 9 3 2 4 1 3 5 0 4 8 1 5 5 2 6 6 3 7 7 2 8 3 4 9 5 1 10 2 2 11 5 2 12 2 2 13 8 2 14 12 4 15 7 4 16 3 2 17 4 0 18 8 2 19 6 1 20 2 4 21 3 1 22 4 1 23 4 1 24 4 3 25 2 2 26 5 5 27 2 1 28 0 1 29 5 4 30 3 6
- Related Articles
- How to delete rows in an R data frame?
- How to convert rows in an R data frame to list?
- How to remove empty rows from an R data frame?
- How to find the unique rows in an R data frame?
- How to sort an R data frame rows in alphabetical order?
- How to remove last few rows from an R data frame?
- How to convert columns of an R data frame into rows?
- How to remove rows in an R data frame using row names?
- How to extract unique combination of rows in an R data frame?
- How to merge rows having same values in an R data frame?
- How to remove rows that contains all zeros in an R data frame?
- How to count the number of duplicate rows in an R data frame?
- How to find the standard deviation for rows in an R data frame?
- How to subset rows of an R data frame using grepl function?
- How to randomly sample rows from an R data frame using sample_n?

Advertisements