Re: [R] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix

2011-07-20 Thread Joshua Wiley
Hi, I am not sure about "correct", but R stores logical values TRUE/FALSE as 1/0 already so simply changing the mode would suffice: mode(x) <- "numeric" alternately x + 0 HTH, Josh On Wed, Jul 20, 2011 at 8:16 AM, Julian TszKin Chan wrote: > Hi all, > > Suppose I have a matrix of logical va

Re: [R] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix

2011-07-20 Thread David Winsemius
Two further methods: > x+0 [,1] [,2] [,3] [1,]101 [2,]010 [3,]101 > mode(x)<- "numeric"; x [,1] [,2] [,3] [1,]101 [2,]010 [3,]101 On Jul 20, 2011, at 11:27 AM, Sarah Goslee wrote: How about this: x<-matrix(c(T

Re: [R] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix

2011-07-20 Thread Sarah Goslee
How about this: > x<-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) > x [,1] [,2] [,3] [1,] TRUE FALSE TRUE [2,] FALSE TRUE FALSE [3,] TRUE FALSE TRUE > ifelse(x, 1, 0) [,1] [,2] [,3] [1,]101 [2,]010 [3,]101 Sarah On Wed, J