[R] combine two columns
Petr Pikal
petr.pikal at precheza.cz
Tue Nov 29 15:00:40 CET 2005
Hallo
On 28 Nov 2005 at 18:47, Georg Otto wrote:
To: r-help at stat.math.ethz.ch
From: Georg Otto <georg.otto at tuebingen.mpg.de>
Date sent: Mon, 28 Nov 2005 18:47:38 +0100
Subject: [R] combine two columns
> Hi,
>
> I have an R programming problem and I havent found anything in the
> documentation yet:
>
> I have a data matrix, in which two neighbouring columns represent
> replicates of the same experiment, e.g. something like this:
>
> A A B B C C
> row1 1 1 1 2 2 2
> row2 1 1 1 1 1 2
Not very neat but
> tabul
A A.1 B B.1 C C.1
row1 1 1 1 2 2 2
row2 1 1 1 1 1 2
> logmat<-as.logical(apply(tabul,1,diff))
> dim(logmat)<-c(2,5)
> logmat
[,1] [,2] [,3] [,4] [,5]
[1,] FALSE TRUE FALSE FALSE FALSE
[2,] FALSE FALSE FALSE FALSE TRUE
> liche
function (x)
{
indices <- seq(along = x)
x[indices%%2 == 1]
}
> !logmat[,liche(1:5)]
[,1] [,2] [,3]
[1,] TRUE TRUE TRUE
[2,] TRUE TRUE FALSE
>
Finally gives the result you want.
HTH
Petr
>
> I would like to test, if the values for the two replicates in a row
> are the same or if they differ and generate a new matrix with the
> results of the tests, something like this:
>
> A B C
> row1 T F T
> row2 T T F
>
> Any hint will be appreciated!
>
> Georg
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list