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
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
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
Hi all,
Suppose I have a matrix of logical value:
x<-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3)
I would like to change the value of FALSE to 0 and TRUE to 1. An
obvious way to do it is :
y<-as.numeric(x)
However this method doesn't keep the dim of x. I also need to copy
4 matches
Mail list logo