Introduction
In one of my previous articles, we learned practically about the Data Frame in R. Now, we will learn to perform the operations on R Data Frame - adding and removing Rows to a Data Frame in R. Apart from this, we will also learn to merge a Data Frame in R. At last, we will learn to summarize the Data Frame in R.
Let's start now.
Data Frame in R
Data Frame in R is a data type. It is a two-dimensional object. It can contain different data type elements like numeric, character or logical in different columns. Here, one thing we need to remember is that while creating it, in any single column, all the elements should be of the same type i.e., either numeric, character, logic or something else.
We had created a Data Frame of the world population in R, as shown below, using the following code.

#Creating Rank Vector
Rank <- 1:10
#Creating Country Vector
Country <- c("China", "India", "United States", "Indonesia", "Pakistan", "Brazil",
"Nigeria", "Bangladesh", "Russia", "Mexico")
#Creating 2019 Population Vector
Population.2019 <- c(1433783686, 1366417754, 329064917, 270625568, 216565318,
211049527, 200963599, 163046161, 145872256, 127575529)
#Creating 2018 Population Vector
Population.2018 <- c(1427647786, 1352642280, 327096265, 267670543, 212228286,
209469323, 195874683, 161376708, 145734038, 126190788)
#Creating Growth Rate Vector
Growth.Rate <- c("0.43%", "1.02%", "0.60%", "1.10%", "2.04%", "0.75%", "2.60%",
"1.03%", "0.09%", "1.10%")
#Creating Data Frame using above vectors
DataFrame.WorldPopulation <- data.frame(Rank, Country, Population.2019, Population.2018,
Growth.Rate)
#Printing the above Data Frame
DataFrame.WorldPopulation
Now, we will perform operations on the above Data Frame in R Studio which are as shown below.
Printing Structure of Data Frame/R Object
We can print and observe the structure of the Data Frame in R by simply using the str(<object>) function as shown below. To know more about str(<obj>) function, you can follow the R documentation str() function in R.
#Printing Structure / Dimension of DataFrame.WorldPopulation Before Row Addition
str(DataFrame.WorldPopulation)
It will give the following result with the overall structure, like the number of rows, columns, some of the elements of each column.

Adding Observation/Row To R Data Frame
To add or insert observation/row to an existing Data Frame in R, we use rbind() function. We can add single or multiple observations/rows to a Data Frame in R using rbind() function.
The basic syntax of rbind() is as shown below.
rbind(<old existing object>, <new object to be added>)
Now we shall learn to add the observations/rows using rbind() below.
Adding Single Observation / Row To R Data Frame
To add a single observation at a time to an existing data frame we will use the following steps.
- Create a new Data Frame of the same number of variables/columns.
- Name the newly created Data Frame variable as of old Data Frame in which you want to add this observation.
- Use the rbind() function to add a new observation.
The above said steps have been implemented in the below example.
#Japan Population Data Frame - Step 1
Japan.Population <- data.frame(11, "Japan", 126860301, 127202192, "-0.27%")
#Naming the Data Frame - Step 2
names(Japan.Population) <- c("Rank", "Country", "Population.2019", "Population.2018", "Growth.Rate")
#Using rbind() function to insert above observation
WorldPopulation.Newdf <- rbind(DataFrame.WorldPopulation, Japan.Population)
Now we have already inserted the observation/row to the existing Data Frame of name DataFrame.WorldPopulation and created a new data frame of name WorldPopulation.Newdf as shown in the above example.
Now, we can easily see the above added observation by printing the new Data Frame, as shown below.
#Printing new Data Frame after a row insertion
WorldPopulation.Newdf

We can check the structure of the newly created Data Frame using the str() function.
#Printing the Structure of Data Frame
str(WorldPopulation.Newdf)

As we can see clearly the structure of new data frame of the name WorldPopulation.New has been changed. Previously, it had only 10 observations but now, it has 11 observations after inserting one observation. Here, the variable has the same 5 variables in both data frames as we have not done any insertion/removal to the variable/column of the data frame.
Adding Multiple Observations/Rows To R Data Frame
Adding single observations one by one is a repetitive, time-consuming, as well as, a boring task. Hence we will learn to add multiple observations at a time in one attempt. Here also we will use the same rbind() function.
We can use the below steps to add multiple observations at a time.
- Create a new Data Frame of the same number of variables/columns with the help of vector.
- Name the newly created Data Frame variable as of old Data Frame in which you want to add these observations.
- Use the rbind() function to add new observations.
The above steps are shown below.
#Creating Data Frame of multiple variable/column using Vector
#New Country Population
Df.NewCountryPopulation <- data.frame(c(11, 12, 13, 14, 15),
c("Japan", "Ethiopia", "Philippines", "Egypt", "Vietnam"),
c(10, 10, 10, 10, 10),
c(10, 10, 10, 10, 10),
c("5%", "10%", "12%", "14%", "19%"))
#Naming the above Data Frame
names(Df.NewCountryPopulation) <- c("Rank", "Country", "Population.2019", "Population.2018", "Growth.Rate")
#Adding observations using rbind() function
Df.NewWorldPopulationAfterObs <- rbind(DataFrame.WorldPopulation, Df.NewCountryPopulation) 









Join the conversation! Your thoughts help the community grow.