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
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
On 11/28/05 12:47 PM, "Georg Otto" <georg.otto at tuebingen.mpg.de> wrote:> 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 > > 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!x <- matrix(c(1,1,1,2,2,2,1,1,1,1,1,2),nr=2,byrow=TRUE) colnames(x) <- c('A','A','B','B','C','C') aggregate(t(x),by=list(colnames(x)),function(y) {length(unique(y))==1}) This should be close, I think. Sean
Hello,
Following should work.
m <- matrix(round(runif(16,0,2)),nrow=2)
colnames(m) <-
c("A","A","B","B","C","C","D","D")
m2 <- m #matrix(, nrow=dim(m)[1], ncol=dim(m)[2]/2)
z <- 1
ss <- seq(1,dim(m)[2],2)
for(j in ss){
for(i in 1:dim(m)[1]){
m2[i,j] <- substring(m[i,ss[z]] == m[i,ss[z]+1],1,1)
}
z <- z + 1
}
m2 <- m2[,ss]
colnames(m2) <- colnames(m)[ss]
When your data set is large, then you should try to code this using
apply.
Best,
Matthias
>
> 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
>
> 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
>
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 2Not very neat but> tabulA 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.htmlPetr Pikal petr.pikal at precheza.cz
Yet another way...
a<-matrix(c(1,1,1,1,1,1,2,1,2,1,2,2),nr=2)
x<-c("A","B","C")
colnames(a)<-sort(rep(x,2))
compare<-function(x,a){all(a[1,colnames(a)==x]==a[1,x][1])}
v<-function(y,x,compare,a){sapply(x,compare,a=a[y,,drop=F])}
t(sapply(1:nrow(a),v,x,compare,a))
--Bill
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Georg Otto
Sent: Monday, November 28, 2005 12:48 PM
To: r-help at stat.math.ethz.ch
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
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
Try this:> is.odd <- !array(0:1, ncol(mat)) > mat[,is.odd] == mat[,!is.odd]A B C row1 TRUE FALSE TRUE row2 TRUE TRUE FALSE On 11/28/05, Georg Otto <georg.otto at tuebingen.mpg.de> wrote:> 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 > > 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 >
Dear Group, I have a machine which has a 64bit Intel?? Xeon? Processor 3.00GHz, 2MB L2 Cache 6T302N - [ 221-7984 ] processor. (Dell Precision Workstation 670n Intel?? Xeon? Processor) The OS is RedHat Enterprise Linux version 4 (for 64bit). I went to /bin/linux/redhat/el4/i386 on CRAN FTP site. I have no clue if any of these RPMs are suitable for this machines configuration. Could any one point me to an appropriate RPM that I can download and install it on this machine. Thank you. Sr
And here is one minor variation of this: odd <- seq(1, ncol(mat), 2) mat[,odd] == mat[,odd+1] On 11/29/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> Try this: > > > is.odd <- !array(0:1, ncol(mat)) > > mat[,is.odd] == mat[,!is.odd] > A B C > row1 TRUE FALSE TRUE > row2 TRUE TRUE FALSE > > On 11/28/05, Georg Otto <georg.otto at tuebingen.mpg.de> wrote: > > 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 > > > > 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 > > >