Test whether Two Data Frames are Identical in R (Example Code)

In this R programming tutorial you’ll learn how to compare two data frames and check if they are the same.

Example Data

df_A <- data.frame(x = LETTERS[7:2],    # Constructing first data set
                   y = 15:10,
                   z = 3:8)
df_A
#   x  y z
# 1 G 15 3
# 2 F 14 4
# 3 E 13 5
# 4 D 12 6
# 5 C 11 7
# 6 B 10 8
df_B <- data.frame(x = LETTERS[7:2],    # Constructing second data set
                   y = 15:10,
                   z = 3:8)
df_B
#   x  y z
# 1 G 15 3
# 2 F 14 4
# 3 E 13 5
# 4 D 12 6
# 5 C 11 7
# 6 B 10 8

Example: Comparing whether Two Data Frames are Identical in R

all.equal(df_A, df_B)                   # Test if data frames are the same
# [1] TRUE

Further Resources & Related Tutorials

In the following, you can find some further resources that are related to the content of this post.

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