Related Articles
Comparing two data sets in R
• Last Updated : 16 Mar, 2021

There may be a situation where we have to compare datasets to do data analysis, with having the same structure but differences in the data. So to identify what is changed in the dataset and to get a summary to which extent it is changed. We can use the compare package in R. We can easily use this package to compare two data frames and check out the summary of what extent it is changed.

The function comparedf() is used to compare two dataframes in R. The function takes two dataframes and then check them for comparison.

Syntax: comparedf(dataset1,dataset2)

Parameters:

• dataset1, dataset2: These are the two datasets to be compared.

Also, we can see the summary of the difference as:

Syntax:

`summary(comparedf(dat,dat2)`

Approach:

• Import library
• We have to simply create datasets.
• Pass the dataset as a parameter in the comparedf() function.
• It will detect the difference if any.
• Use the summary method to check the complete summary.

Example1 :

## R

 `library``(arsenal)`` ` ` ` `dat <- ``data.frame``(``SSN = ``c``(23,434,565,878,231),  ``Name=``c``(``"hamburgers"``,``"butter"``,``"cheeze"``,``"cofee"``,``"teacher"``),  ``Age = ``c``(7,8,6,43,56),  ``Gender = ``c``(0,1,0,1,0)``)`` ` `dat2 <- ``data.frame``(``SSN = ``c``(210,345,456,745,245),  ``Name=``c``(``"fruits"``,``"cupcakes"``,``"mangoes"``,``"toffee"``,``"student"``),  ``Number= ``c``(3,5,5,6,77),  ``Different = ``c``(0,0,1,1,0)``)`` ` `summary``(``comparedf``(dat,dat2))`

Output: Example 2:

## R

 `library``(arsenal)`` ` ` ` `dat <- ``data.frame``(``Rollnumber = ``c``(1,2,3,4,5),  ``Name=``c``(``"Akash"``,``"John"``,``"Tina"``,``"Kakashi"``,``"Brad"``),  ``Age = ``c``(7,8,6,5,7),  ``Marks = ``c``(78,98,76,67,89)``)`` ` `dat2 <- ``data.frame``(``Rollnumber = ``c``(1,2,3,4,5),  ``Name=``c``(``"Akash"``,``"John"``,``"Tina"``,``"Kakashi"``,``"Brad"``),  ``Age = ``c``(7,9,6,7,8),  ``Marks= ``c``(78,98,56,87,67)``)`` ` `comparedf``(dat,dat2)`

Output: My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.7338032,"math_prob":0.9876803,"size":1736,"snap":"2021-21-2021-25","text_gpt3_token_len":590,"char_repetition_ratio":0.13972287,"word_repetition_ratio":0.16949153,"special_character_ratio":0.3675115,"punctuation_ratio":0.26213592,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9810065,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,2,null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-14T20:55:41Z\",\"WARC-Record-ID\":\"<urn:uuid:5ddffe74-b3b6-47f2-99f7-14cd6c44ef36>\",\"Content-Length\":\"95869\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:147824b2-bbd2-494c-aa1a-7219cd4fe220>\",\"WARC-Concurrent-To\":\"<urn:uuid:032517e2-3cd6-4c3b-b9a8-a3eac8647124>\",\"WARC-IP-Address\":\"23.50.51.201\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/comparing-two-data-sets-in-r/?ref=rp\",\"WARC-Payload-Digest\":\"sha1:OGSHT2CISWEEW7WGMYDNFVEYCTPPHFOS\",\"WARC-Block-Digest\":\"sha1:4AAG3ZV6VST4ANC6VUBRMTKPIIJ6A4HV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243991207.44_warc_CC-MAIN-20210514183414-20210514213414-00498.warc.gz\"}"}