Use identical . This is the R "scalar" comparison operator; it returns a single boolean, not a vector.
apply(A, 2, identical, a)
If A is a data frame in your real case, you'd better use sapply or vapply , because apply forces it to be entered into the matrix.
d <- c("a", "b", "c") B <- data.frame(a, b, c, d) apply(B, 2, identical, a)
But note that data.frame enforces character inputs into factors, unless you ask otherwise:
sapply(B, identical, d)
Identity is also significantly faster than using all + == :
library(microbenchmark) a <- 1:1000 b <- c(1:999, 1001) microbenchmark( all(a == b), identical(a, b))
source share