I have three arrays that have the same dimensions but what I need is to replace values in dat1
by the corresponding values from dat2
when only corresponding values in dat3
are higher than 0.2.
data:
dat1 <- array(1:60, c(3,5,4))
dat2 <- array(rnorm(60), c(3,5,4))
dat3 <- array(rnorm(60), c(3,5,4))
Another option, creating an index first and then using it to subset:
Edit after comment - a small performance comparison:
For the sample data, indexing is ~5 times faster than ifelse.
If you have two restrictions for the replacement index just use the following index instead: