"final_states" - "", "" list,
final_states %in% list(state)
mapply, , "" "final_states" ( , )
f1 <- function(x,y) all(x==y)
mapply(f1, final_states, list(state))
rbind , , "" "" "m1".
m1 <- do.call(rbind, final_states)
m1[,1]==state[1] & m1[,2]==state[2]
Update
TRUE/FALSE
any(mapply(f1, final_states, list(state)))
any(final_states %in% list(state))
list(state) %in% final_states
"" fmatch fastmatch
library(fastmatch)
fmatch(list(state), final_states) >0
@Richard Sciven base R , , fmatch
set.seed(295)
final_states <- replicate(1e6, sample(1:20, 20, replace=TRUE),
simplify=FALSE)
state <- final_states[[151]]
richard <- function() {Position(function(x) identical(x, state),
final_states, nomatch = 0) > 0}
Bonded <- function(){any( sapply(final_states, identical, state) )}
akrun2 <- function() {fmatch(list(state), final_states) >0}
akrun1 <- function() {f1 <- function(x,y) all(x==y)
any(mapply(f1, final_states, list(state)))}
library(microbenchmark)
microbenchmark(richard(), Bonded(), akrun1(), akrun2(),
unit='relative', times=20L)
#Unit: relative
# expr min lq mean median uq
# richard() 35.22635 29.47587 17.49164 15.66833 14.58235
# Bonded() 109440.56885 101382.92450 55252.86141 47734.96467 44289.80309
# akrun1() 167001.23864 138812.85016 75664.91378 61417.59871 62667.94867
# akrun2() 1.00000 1.00000 1.00000 1.00000 1.00000
# max neval cld
# 14.62328 20 a
# 46299.43325 20 b
# 63890.68133 20 c
# 1.00000 20 a