Kppatel Patel - 10 months ago 34

R Question

I have list as follows

`l = list(c("a", "b", "c"), c("a", "b", "c"), c("a", "b", "c"))`

I want to check that each of them contain same values using apply family functions.

I want following answer

`TRUE, TRUE, TRUE`

Answer

We can use `duplicated`

```
duplicated(l)|duplicated(l, fromLast=TRUE)
#[1] TRUE TRUE TRUE
```

If we need to compare all the combinations of `list`

elements, `combn`

is another way

```
combn(seq_along(l), 2, FUN= function(x) all(l[[x[1]]] == l[[x[2]]]))
#[1] TRUE TRUE TRUE
```

Source (Stackoverflow)