Using identical() in R with multiple vectors

前端 未结 6 607
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 15:48

Suppose that I have five vectors:

A<-1:10
B<-1:10
C<-1:10
D<-1:10
E<-1:12

I could test two at a time using identical( ).

6条回答
  •  春和景丽
    2020-12-15 16:29

    I would just pick one, say A, and do all pair-wise comparisons with it.

    all(sapply(list(B, C, D, E), FUN = identical, A))
    # [1]  FALSE
    

    Remove the all() to see the not identical one(s)

    sapply(list(B, C, D, E), FUN = identical, A)
    # [1]  TRUE  TRUE  TRUE FALSE
    

    identical ought to be transitive, so if A is identical to C and to D, then C should be identical to D.

    (Thanks to @docendo discimus for simplified syntax.)

提交回复
热议问题