[R] combine two columns
Sean Davis
sdavis2 at mail.nih.gov
Tue Nov 29 14:34:39 CET 2005
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
More information about the R-help
mailing list