How to compare the contents of a column of the same data table I have this table: 



and I want to get the rows that are equal to the first three columns, like this: 



I've tried these functions, but when I get the index of the lines, r doesn't give the output that I want:

df$obj&lt;-sapply(c("sample1", "sample2", "sample3"), function (comparison) {
    df$sample1 == df[comparison]
})
Loop through 3 columns by row using apply, then convert toupper case (as we want a same as A), get unique, and get lengths, if length is 1 then all 3 values are equal:

df1[ lengths(
  apply(df1[, 1:3], 1, function(i) unique(toupper(i)))
  ) == 1, ]


This would scale better if we want to compare 4, 10, n(?) columns.