check whether all elements of a list are in equal in R

前端 未结 5 620
挽巷
挽巷 2021-01-02 09:34

I have a list of several vectors. I would like to check whether all vectors in the list are equal. There\'s identical which only works for pairwise comparison.

5条回答
  •  情歌与酒
    2021-01-02 10:35

    I woud do:

    all.identical <- function(l) all(mapply(identical, head(l, 1), tail(l, -1)))
    
    all.identical(test_true)
    # [1] TRUE
    all.identical(test_false)
    # [1] FALSE
    

提交回复
热议问题