Skip to content
Prev 293225 / 398503 Next

Data frame vs matrix quirk: Hinky error message?

Hello,


Bert Gunter wrote
Actually, it works, as long as the logical index matrix has the same
dimensions as the data frame.


zmat <- matrix(1:12,nr=4)
zdf <- data.frame(zmat)

# Numeric index matrix.
ix <- cbind(1:2,2:3)
# Logical index matrix.
ix2 <- row(zdf) == ix[, 1] & col(zdf) == ix[, 2]

zmat[ix]
zmat[ix2]

zdf[ix]
zdf[ix2]

zmat[ix] <- NA
zmat
# So far so good,
# But now, as already seen, error
zdf[ix] <- NA
# Works
zdf[ix2] <- NA
zdf

It even makes sense...

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Data-frame-vs-matrix-quirk-Hinky-error-message-tp4601254p4601507.html
Sent from the R help mailing list archive at Nabble.com.