I have an array:
a <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0
maybe you want ifelse:
ifelse
a <- c(1,1,1,1,0,0,0,0,2,2) ifelse(a>0,a/sum(a),1) [1] 0.125 0.125 0.125 0.125 1.000 1.000 1.000 1.000 [9] 0.250 0.250