[R] dimension-preserving matrix coersion

Murat Tasan mmuurr at gmail.com
Mon Sep 28 01:14:16 CEST 2009


HA!  yeah, that'll do it!  forgot that mode() can be used to set modes
as well as get them.

thanks much!

-murat

On Sep 27, 7:10 pm, jim holtman <jholt... at gmail.com> wrote:
> How about this:
>
> > m <- matrix(c(0, 1, 1, 0), ncol = 2)
> > mode(m) <- 'logical'
> > m
>
>       [,1]  [,2]
> [1,] FALSE  TRUE
> [2,]  TRUE FALSE
>
>
>
>
>
>
>
> On Sun, Sep 27, 2009 at 6:59 PM, Murat Tasan <mmu... at gmail.com> wrote:
> > 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?
>
> > ______________________________________________
> > R-h... at r-project.org mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list