chance<-c(0.11,0.12,0.13,0.14,0.15)
aaa<-function(x,y) {
assignChance <- function (a,b,v) {
if (a == 0)
if (b == 0) 1-v
else v
else
if (b == 0) 0
else 1
}
sapply(x,assignChance,y,chance) # this is wrong
}
aaa(c(1,1,0,0,1),c(1,1,1,0,0))
I would expect the outcome as: 1, 1, 0.13, 0.86, 0
Is there any better way for this function. I feel my current attemp is quite ugly as in a functional language I can just use Array.map3
plue pattern match
.
Is there a vector version of switch
just like ifelse
?