Skip to content
Prev 43239 / 398513 Next

conditional assignment

On Mon, 26 Jan 2004, Simon Cullen wrote:

            
assignment returns the new value of zz, which as it is all non-zero
coerces to the logical vector T T T
Rather better I think is

zz <- ifelse(z > 2, z, zz)

or even

ind <- z > 2
zz[ind] <- z[ind]