我想对向量中的每一行使用一个函数。
当我尝试输入代码时,会收到以下消息: 条件的长度> 1,并且只会使用第一个元素
function(Inn, x, y, z, xx, b, i, Dp){
if (Inn == 0) {
if (runif(1) <= x) { # success.probability.imitation
absorptive.capacity <- max(y, z)
}
else{
absorptive.capacity <- min(x, x + b/sqrt(i) - Dp)
}
} else{
if (runif(1) <= xx) { # sucess innovation
absorptive.capacity <- y + b / sqrt(i)
} else{
absorptive.capacity <- y + b / sqrt(i) - Dp
}
}
if (absorptive.capacity > 1) {
absorptive.capacity = 1
}
return(absorptive.capacity)
}
absorptive.capacity(c(0, 1), c(0.5, 0), c(0.7, 0.8), 0.7, c(0, 06), 0.5, c(64, 94), 0.06)
我想在转换后返回每个值,这是我函数的目的。有人可以帮助我吗?
答案 0 :(得分:-1)
absorptive.capacity<-function(Inn, x, y, z, xx, b, i, Dp){
ifelse( Inn == 0,
ifelse(runif(1) <= x,
absorptive.capacity <- max(y, z),
absorptive.capacity <- min(x, x + b/sqrt(i) - Dp)),
ifelse(runif(1) <= xx,
absorptive.capacity <- y + b / sqrt(i),
absorptive.capacity <- y + b / sqrt(i) - Dp))
ifelse(absorptive.capacity > 1,
absorptive.capacity == 1,
absorptive.capacity == absorptive.capacity)
return(absorptive.capacity)
}