Append New Row to Empty Data Frame in R (Example Code)

On this page, I’ll show how to append a new row to an empty data frame in R.

Creating Example Data

my_df <- data.frame(v = numeric(0),    # Empty data frame in R
                    w = numeric(0),
                    x = numeric(0),
                    y = numeric(0),
                    z = numeric(0))
my_df                                  # Show empty data in RStudio
# [1] v w x y z
# <0 rows> (or 0-length row.names)

Example: Use Index Position to Append Row to Empty Data Frame

my_df[1, ] <- c(5, 1, 3, 7, 0)         # Adding new row
my_df                                  # Showing new data frame with row
#   v w x y z
# 1 5 1 3 7 0

Related Articles & Further Resources

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

Leave a Reply

Your email address will not be published.

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