[R] dimension-preserving matrix coersion
Murat Tasan
mmuurr at gmail.com
Mon Sep 28 00:59:26 CEST 2009
i've written a function to coerce a matrix (e.g. from numeric to
logical), but i'd like to know if someone has a more elegant method
for this:
> m <- matrix(c(0, 1, 1, 0), ncol = 2)
> m <- as.logical(m)
> m
[1] FALSE TRUE TRUE FALSE
i'd like 'm' to still be a matrix with the original dimensions. in my
function to do this, i coerce 'm' to a logical, then re-form it as a
matrix, which seems like an extra (possibly bug-introducing) step that
might be avoided if i knew of some "hidden" feature that might permit
this in one fell swoop.
any ideas?
More information about the R-help
mailing list