Compare if two dataframe objects in R are equal?

前端 未结 4 631
后悔当初
后悔当初 2020-12-23 19:33

How do I check if two objects, e.g. dataframes, are value equal in R?

By value equal, I mean the value of each row of each column of one dataframe is equal to the va

4条回答
  •  长情又很酷
    2020-12-23 20:11

    It is not clear what it means to test if two data frames are "value equal" but to test if the values are the same, here is an example of two non-identical dataframes with equal values:

    a <- data.frame(x = 1:10)
    b <- data.frame(y = 1:10)
    

    To test if all values are equal:

    all(a == b) # TRUE
    

    To test if objects are identical (they are not, they have different column names):

    identical(a,b) # FALSE: class, colnames, rownames must all match.
    

提交回复
热议问题