Append Empty Row (NA Values) to Bottom of Data Frame in R (Example Code)

In this R tutorial you’ll learn how to append an empty row to the bottom of a data frame.

Creation of Example Data

data(iris)                      # Importing iris data set
tail(iris)                      # Print bottom rows of iris
#     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
# 145          6.7         3.3          5.7         2.5 virginica
# 146          6.7         3.0          5.2         2.3 virginica
# 147          6.3         2.5          5.0         1.9 virginica
# 148          6.5         3.0          5.2         2.0 virginica
# 149          6.2         3.4          5.4         2.3 virginica
# 150          5.9         3.0          5.1         1.8 virginica

Example: Adding an Empty Row with NA Values to a Data Frame

iris[nrow(iris) + 1, ] <- NA    # Appending an empty row
tail(iris)                      # Print updated iris data frame
#     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
# 146          6.7         3.0          5.2         2.3 virginica
# 147          6.3         2.5          5.0         1.9 virginica
# 148          6.5         3.0          5.2         2.0 virginica
# 149          6.2         3.4          5.4         2.3 virginica
# 150          5.9         3.0          5.1         1.8 virginica
# 151           NA          NA           NA          NA      <NA>

Related Articles

You may find some related R programming language tutorials on topics such as missing data, numeric values, variables, and loops in the following list.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top