compare two columns in a data frame by data

61 Views Asked by At

I have two dataframe, lets call them DF1 and DF2, respectively, that look like the next:

|Symbol |   Date    | volume |price |
|------------------------------------
|A      |2014-01-01 | 1      |   5  |
|A      |2014-01-02 | 3      |   8  |
|A      |2014-01-03 | 7      |   4  |
|A      |2014-01-07 |3       |   6  |
|A      |2014-01-08 |34      |   7  |
|A      |2014-01-09 |45      |  34  |
|A      |2014-01-10 |4       |   5  | 
|A      |2014-01-11 |9       |   7  |
|A      |2014-01-14 |8       |   6  |
|A      |2014-01-15 |4       |   4  |
|A      |2014-01-16 |0       |   7  |
|A      |2014-01-17 |4       |   7  |

|   Date    | returns|
|--------------------
|2014-01-01 | 4      | 
|2014-01-02 | 6      |  
|2014-01-03 | 8      |  
|2014-01-07 | 2      |  
|2014-01-08 | 14     |   
|2014-01-09 | 5      |  
|2014-01-10 | 1      |    
|2014-01-11 | 2      |   
|2014-01-14 |8       |  
|2014-01-15 |4       |  
|2014-01-16 |0       |   
|2014-01-17 |4       |

And I would like to find a way to check if all the rows of the date column in the DF1 dataframe are equal to the corresponding entry of the date column in the DF2 dataframe and I don't know how to do it.

Maybe you can help me... thank you very much!

1

There are 1 best solutions below

4
tjebo On

Worth to mention the new package from the Hadley-verse: waldo

Gives really nice, concise, and informative messages with respect to the differences.

library(waldo)

compare(df1$Date, df2$Date)
#> ✓ No differences

data

# devtools::install_github("alistaire47/read.so")
df1 <- read.so::read_md("|Symbol |   Date    | volume |price |
  |------------------------------------
  |A      |2014-01-01 | 1      |   5  |
  |A      |2014-01-02 | 3      |   8  |
  |A      |2014-01-03 | 7      |   4  |
  |A      |2014-01-07 |3       |   6  |
  |A      |2014-01-08 |34      |   7  |
  |A      |2014-01-09 |45      |  34  |
  |A      |2014-01-10 |4       |   5  | 
  |A      |2014-01-11 |9       |   7  |
  |A      |2014-01-14 |8       |   6  |
  |A      |2014-01-15 |4       |   4  |
  |A      |2014-01-16 |0       |   7  |
  |A      |2014-01-17 |4       |   7  |")

  df2 <- read.so::read_md("|   Date    | returns|
  |--------------------
  |2014-01-01 | 4      | 
  |2014-01-02 | 6      |  
  |2014-01-03 | 8      |  
  |2014-01-07 | 2      |  
  |2014-01-08 | 14     |   
  |2014-01-09 | 5      |  
  |2014-01-10 | 1      |    
  |2014-01-11 | 2      |   
  |2014-01-14 |8       |  
  |2014-01-15 |4       |  
  |2014-01-16 |0       |   
  |2014-01-17 |4       |")