It is easier and more straightforward than any of the suggestions
so far. Simply multiply the matrix by 1, or add 0 to it:
x<-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3)
1*x
# [,1] [,2] [,3]
# [1,]101
# [2,]010
# [3,]101
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
Am I correct in thinking that you actually want a function that will
take the three row matrix
Ystart <- matrix(c(1:3, 34,-56,27), ncol=2) and return the 4 column
matrix offered?
As it is I see no way that we could know what rule you wanted to apply
to that four row X matrix to get the 9
Hello,
I have a matrix such as
> X = matrix(c(1:4,29,32,56,-45), ncol=2)
and I want one like
> Y=matrix(c(
1 , 34 , 1 , 34 ,
2 , -56 , 1 , 34 ,
3 , 27 , 1 , 34 ,
1 , 34 , 2 , -56 ,
2 , -56 , 2 , -56 ,
3 , 27 , 2 , -56 ,
1 , 34 , 3 , 27 ,
2 , -56 , 3 , 27 ,
3 , 27 , 3 , 27 ), ncol=4, byrow=T)
Ho
7 matches
Mail list logo