Comparing two Excel files in R and returning different titles

0 votes

I have to compare two Excel spreadsheets as part of a project at work to determine whether a title has been added to or removed from the second Excel sheet (Book 2). Although the code I wrote is effective, it is also not very aesthetically pleasing and is challenging to understand for someone without any prior knowledge of R.

In order for my coworkers to comprehend and make changes to the differences, I want to compare two Excel files and output the differences in a simple manner. The result should ideally be a table that organizes the data so that it is simple to find and edit. I value all the assistance.

structure(list(Title = c("D", "Mortal Kombat", "Godzilla",
"Wonder", "Suicide Squad", "Mulan"), Studio = c("X", "X",
"X", "X", "X", "Y"), Type = c("Special", "Special", "Special",
"Special", "Special", "Special")), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -6L))


structure(list(Title = c("D", "Mortal Kombat", "Godzilla",
"Wonder", "Trolls"), Studio = c("X", "X", "X", "X", "X"
), Type = c("Special", "Special", "Special", "Special", "Special"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-5L))

library("compareDF")
library("readxl")

dat <- read_xlsx("Book1.xlsx")
dat2 <- read_xlsx("Book2.xlsx")


compare_df(dat, dat2)
Oct 14 in Others by Kithuzzz
• 20,660 points
86 views

1 answer to this question.

0 votes

Solution:

library(tidyverse)
dat <- read_xlsx("Book1.xlsx")
dat2 <- read_xlsx("Book2.xlsx")

book1_output <- anti_join(dat,dat2, by = "Title") %>% mutate(source = "Book1")
book2_output <- anti_join(dat2,dat, by = "Title") %>% mutate(source = "Book2")

final_output <- rbind(book1_output,book2_output)
answered Oct 14 by narikkadan
• 37,660 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

Word Mail Merge with Excel data has to be saved in different files with custom names

Try this: Public Sub Mail_Merge() On Error GoTo ErrH Dim ...READ MORE

answered Nov 6 in Others by narikkadan
• 37,660 points
53 views
0 votes
1 answer

Want to compare two columns in excel

Hello To compare two columns in excel ...READ MORE

answered Feb 9 in Others by gaurav
• 22,040 points
311 views
0 votes
1 answer

How to open .xlsx files in MS Excel from VS Code?

Hello, to open xlxs files, or files ...READ MORE

answered Feb 17 in Others by gaurav
• 22,040 points
281 views
0 votes
1 answer

Excel, How to split cells by comma delimiter into new cells

The Excel manual method: choose Text to Column ...READ MORE

answered Oct 3 in Others by narikkadan
• 37,660 points
70 views
0 votes
1 answer

Conversion of PDF file to Excel in R

I looked at the pdf, and it ...READ MORE

answered Oct 16 in Others by narikkadan
• 37,660 points
80 views
0 votes
1 answer

Use R to create chart in Excel sheet

Here is a solution utilizing the XLConnect ...READ MORE

answered Nov 10 in Others by narikkadan
• 37,660 points
35 views
0 votes
1 answer

Write from R into template in excel while preserving formatting

you have the XLConnect package. Read the documentation or the vignette of that ...READ MORE

answered Nov 10 in Others by narikkadan
• 37,660 points
45 views
0 votes
1 answer

Download multiple excel files linked through urls in R

Try something along the lines of: for (i ...READ MORE

answered Sep 23 in Others by narikkadan
• 37,660 points
103 views
0 votes
1 answer

Apache POI - watermark in Excel - different appearance in Excel and LibreOffice

There is nothing that apache poi could ...READ MORE

answered Oct 9 in Others by narikkadan
• 37,660 points
138 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP