In this shot, we’ll learn to add a row to an existing data frame.
The data frame in R represents data in a table format with rows and columns.
To add a row to an existing data frame, we use the rbind()
function.
rbind(data frame, row data)
The rbind()
function takes the following parameter values:
data frame
: Represents the data frame object.row data
: Represents the row data we wish to add to the data frame.The rbind()
function returns a modified data frame with a new row.
Let’s illustrate this method with the help of code:
# creating a data frameMy_Data_Frame <- data.frame (Height = c("Tall", "Average", "short"),Body_structure = c("Meso", "Endo", "Ecto"),Age = c(35, 30, 45))# adding a new rowNew_Data_Frame <- rbind(My_Data_Frame, c("Tall", "Meso", 25))New_Data_Frame
My_Data_frame
, using the data.frame()
function. The data frame contains three columns.rbind()
function and add a new row to the existing data frame.New_Data_Frame
.