Re: [R] dimension-preserving matrix coersion

2009-09-27 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Murat Tasan > Sent: Sunday, September 27, 2009 3:59 PM > To: r-help@r-project.org > Subject: [R] dimension-preserving matrix coersion > > i've w

Re: [R] dimension-preserving matrix coersion

2009-09-27 Thread Murat Tasan
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 wrote: > How about this: > > > m <- matrix(c(0, 1, 1, 0), ncol = 2) > > mode(m) <- 'logical' > > m > >       [,1]  [,2] > [1,] FALSE  TRUE > [2,]  TRUE

Re: [R] dimension-preserving matrix coersion

2009-09-27 Thread jim holtman
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 wrote: > i've written a function to coerce a matrix (e.g. from numeric to > logical), but i'd like to know if someo

[R] dimension-preserving matrix coersion

2009-09-27 Thread Murat Tasan
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.