The most efficient way to check if all values in a row are the same or are NA

I want to check if all values in each row are the same, but, NA should be ignored MWE:

library(data.table)
DT=data.table(v1=c(1,2,3),v2=c(1,3,3), v3=c(NA,2,3))

DT
   v1 v2 v3
1:  1  1 NA
2:  2  3  2
3:  3  3  3

desired=c(T,F,T)

desired
[1]  TRUE FALSE  TRUE

Solution 1:

I get an efficient idea

v1 = do.call(pmin, c(DT, na.rm = TRUE))
v2 = do.call(pmax, c(DT, na.rm = TRUE))
v1 == v2