[R] combine two columns

Bill West wjwest at CLEMSON.EDU
Tue Nov 29 15:28:11 CET 2005


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




More information about the R-help mailing list