Is there a more efficient way of doing function 'which' in R?
Try:

1-sum(ftable==1L)/sum(ftable)


Test on larger data:

n &lt;- 1000000
set.seed(21)
ftable &lt;- data.frame(replicate(3, sample.int(4, n, replace = T))-1L)

start.time=Sys.time()
1-length(which(ftable==1))/sum(ftable)
end.time=Sys.time()
end.time-start.time
# Time difference of 0.1981359 secs

start.time=Sys.time()
1-sum(ftable==1L)/sum(ftable)
end.time=Sys.time()
end.time-start.time
# Time difference of 0.06704712 secs


bechmarks:

n &lt;- 1000000
set.seed(21)
ftable &lt;- data.frame(replicate(3, sample.int(4, n, replace = T))-1L)

jz &lt;- function() 1-length(which(ftable==1))/sum(ftable)  
minem &lt;- function() 1-sum(ftable==1L)/sum(ftable)

br &lt;- bench::mark(jz(), minem(), iterations = 50)
br[, 1:7]
# A tibble: 2 x 7
#   expression      min     mean   median      max `itr/sec` mem_alloc
#   &lt;chr&gt;      &lt;bch:tm&gt; &lt;bch:tm&gt; &lt;bch:tm&gt; &lt;bch:tm&gt;     &lt;dbl&gt; &lt;bch:byt&gt;
# 1 jz()         51.2ms   53.8ms   52.6ms   66.3ms      18.6    60.1MB
# 2 minem()      37.7ms   39.9ms   38.5ms     67ms      25.1    45.8MB
# only around 36 % faster