[BioC] table values

Johannes Freudenberg Johannes.Freudenberg at cchmc.org
Mon Sep 25 20:30:38 CEST 2006


Hi Daphne,

can you convert q into a matrix using as.matrix()?  For example:

> q<-as.matrix(table(PL[,c(1,4)]))

Also, you can always use apply() to make a quick-and-dirty for-loop. 
For example

> x <- matrix(rnorm(100), 10)
> apply(matrix(1:10), 1, function(i) mean(x[i,])) #row means
 [1]  0.36618487 -0.27148188  0.22449872  0.36215196  0.15594956 
0.16164272  0.05519145 -0.17158213
 [9] -0.19026337 -0.12838692
> y <- matrix(rnorm(100),10)
> apply(matrix(1:10), 1, function(i) cor(x[i,], y[i,])) #row-wise
correlation between x and y
 [1] -0.569887927  0.008844097 -0.602930234 -0.092437966  0.074451523 
0.099452783  0.199365306
 [8] -0.427166116 -0.488460859 -0.134369206

This is ugly on so many levels but sometimes it saves me a lot of
programming time.  Of course, at least for the first example, there is a
much better solution:

> rowMeans(x)
 [1]  0.36618487 -0.27148188  0.22449872  0.36215196  0.15594956 
0.16164272  0.05519145 -0.17158213
 [9] -0.19026337 -0.12838692

Best,
--Johannes



Johannes Freudenberg
Graduate Student
Division of Biomedical Informatics
TCHRF 8526
Cincinnati Children's Hospital Medical Center
3333 Burnet Avenue
Cincinnati, OH 45229
phone: (513) 636-1424
fax: (513) 636-2056
e-mail: johannes.freudenberg at cchmc.org

>>> "daphne mouzaki (RI)" <daphne.mouzaki at bbsrc.ac.uk> 09/23/06 7:43 AM
>>>
Hi Johannes and thanks for your reply.
 
The PietrLand.csv file is the file that contains the gene name,
regulation (-1,1 down, up), the Breed(Pietrain=1, Landrace=2) and the
Time (1,2,3,..7 which stands for 2,4,8,12,16,24,30 hours that the
samples were taken respectively). Each gene was down or up regulated at
different time points per breed and I want to have these info in a
table. 
To be more specific :
> PL<-read.csv("PietrLand.csv",header=TRUE)
> dim(PL)
[1] 6236    4
> class(PL)
[1] "data.frame"
> PL[1:4,]
            Gene.name Regulation Breed Time
1    Ssc.7157.1.A1_at          1     1    1
2    Ssc.9062.1.A1_at          1     1    1
3 Ssc.14467.2.S1_a_at          1     1    1
4   Ssc.19413.1.A1_at          1     1    1
> q<-table(PL[,c(1,4)]) 
> dim(q)
[1] 2568    7
> q[1:4,]
                     Time
Gene.name             1 2 3 4 5 6 7
  AFFX-Ss_IRP_3_at    1 1 2 0 0 1 1
  AFFX-Ss_IRP_5_at    0 0 1 0 0 0 0
  AFFX-Ss_IRP_M_at    0 0 1 0 0 0 0
  AFFX-SSC-28SrRNA_at 0 0 1 0 1 1 0

What I would like to have is a combination of Time-Breed information
per gene. As you can notice
at different time points genes are differentially expressed ( up-down
regulated) and I want to keep track of the gene behaviour per breed.
More specifically sth like this :
                     
Gene.name                     Breed1                                   
Breed 2
                                      Time min Time max                
Time min  Time max
  AFFX-Ss_IRP_3_at        2            4                              2
            5
  AFFX-Ss_IRP_5_at        1            6                              3
            7
This info mean for example the first gene that the gene was appearing
down regulated at time point 2 and up regulated for time 4 for the first
breed and that the gene was appearing down reg. at time point 2 and up
regulated for time point 5 for the second breed.  The resulting table
should have 2568 X 4 dimensions. I thought about using the function
apply() but it needs a matrix and this is not a matrix. 
 
Cheers,
Daphne

_______________________________________________
Bioconductor mailing list
Bioconductor at stat.math.ethz.ch 
https://stat.ethz.ch/mailman/listinfo/bioconductor 
Search the archives:
http://news.gmane.org/gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list