1

I'm doing data validation of a merged dataframe (A + B) to that of the source dataframes (A and B). I merged A and B dfs and want to ensure they merged properly. The merged df contains all the same variable names as the source dfs. The issue is that the merged df is a different size than that of the source dfs. Is there a simple code to do this?

In excel it would do something like this: =IF(Merged_dataframe!A2=A.xlsx!$A$2,TRUE, result) But for all the rows in the merge dataset and I want it to print out the result true if they match.

I'm new to R and I don't know where to start but did try this:

 A<-First.df
 B<-Second.df
 A_B <- cbind(A, B)
 A_B == A
 A_B == B

But the issue is that the A_B is a different size and so it doesn't work and rightfully so I get this error: ‘==’ only defined for equally-sized data frames

Please help.

Thank you!

Dr.E77
  • 107
  • 6
  • 2
    Can you provide a reproducible example please ? This will answer some question like what are the dimension of the target data frame (same number of lines / column ? variables in common ?). You can use this link to find easy ways to share and specify your problem : [how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – cbo Oct 31 '19 at 15:28

1 Answers1

0

You may want to check data.frame comparison here : Compare two data.frames to find the rows in data.frame 1 that are not present in data.frame 2

Assuming your number of lines is the same in A and B you could all check data.frame difference as such as :

# Using toy data set
x <- iris[1:9,] # use AB_df[ , c("the_column_vector_to check")]
y <- iris[8:11,] # use A_df or B_df

# Test for equality
all.equal(x, x) # TRUE if all equal
#> [1] TRUE
all.equal(x, y) # gives the differences
#> [1] "Attributes: < Component \"row.names\": Numeric: lengths (9, 4) differ >" 
#> [2] "Component \"Sepal.Length\": Numeric: lengths (9, 4) differ"              
#> [3] "Component \"Sepal.Width\": Numeric: lengths (9, 4) differ"               
#> [4] "Component \"Petal.Length\": Numeric: lengths (9, 4) differ"              
#> [5] "Component \"Petal.Width\": Numeric: lengths (9, 4) differ"               
#> [6] "Component \"Species\": Lengths: 9, 4"                                    
#> [7] "Component \"Species\": Lengths (9, 4) differ (string compare on first 4)"
cbo
  • 1,664
  • 1
  • 12
  • 27