R: Bootstrap 仅当 A > B 时的百分比差异

R: Bootstrap Percent Difference only when A > B

我有两组数字 A 和 B。我想做一个 bootstrap 分析,计算每组值之间的百分比差异,但仅适用于 A 组值 > B.

我尝试在下面编写代码,但我得到的所有值都是 0。有人对如何执行此操作有任何建议吗?

A <- c(13,5,8,1,23,4,7,2,14,27)
B <- c(5,7,0.5,10, 1,3, 0.7,2,0.8,4)

percentage_difference <- function(value, value_two) {   
  (value - value_two) / value
}  

n <- 10000 
Per_Dif <- numeric(n)
for (i in 1:n) {
  if(A > B){Per_Dif[i] <- percentage_difference(sample(A, replace = T), sample(B, replace = T))}    
} 

尝试

do.call(c,lapply(1:n, function(boot){
  a <- sample(A, replace = T)
  b <- sample(B, replace = T)
  percentage_difference(a,b)[a>b]
}))