Skip to content

Help with tables

4 messages · PIKAL Petr, Alejandro Rodríguez, T.K.

1 day later
#
Hi

I am not sure but if I remember correctly I had seen similar output in 
Frank Harrel's book. So you could check some function from Hmisc package, 
probably summarize.

Regards

Petr
petr.pikal at precheza.cz

r-help-bounces at r-project.org napsal dne 02.12.2007 03:16:09:
,
variable
<rodrigueza at schwabe.com.mx>
ask
Respiratory
called
my
crossing
and
mention.
"Multiple
(showed
more.
http://www.R-project.org/posting-guide.html
#
Hello everyone.  I want to thank you for your response.

I tried this on weekend to attack my problem:


1)  Turned into factors all my variables to tabulate:

	infec1<-bamas$P2_A
	infec2<-bamas$P2_B
	infec3<-bamas$P2_C
	aglomera<-bamas$QCL_1

	Where bamas is my data frame, P2_A, P2_B and P2_C the infections and QCL_1
the clusters.

2)  Defined a table for each one of the variables I wanted:

	t1<-table(infec1,aglomera)
	t2<-table(infec2,aglomera)
	t3<-table(infec3,aglomera)

3)  Tables generated above are of n1 x 4, n2 x 4, n3 x 4 where n1, n2 and n3
are different and so the dimmensions of my matrices, then if I want to sum
the three tables R showed me the error that they were of
     different dimmensions, so I decided to make them of the same
dimmensions by "filling the holes" (missing rows) with zeros of each row in
each  table in order to transform them into a matrix of N x 4:

     For example, comparing my table t1 with t2, I could see that, in table
1 there where missing rows 7, 10, 12 and 13, and in the case of t3 rows 7
and 12 ;

t1

	aglomera
infec1   1   2   3   4
    1  117  88  76  83
    2   10  10   9   7
    3   15  11  14  14
    4    2   0   1   1
    5    2   3   1   0
    6    1   0   1   0
    8    3   3   0   1
    9    3   1   1   0
    11   0   0   1   1

t3

      aglomera
infec2  1  2  3  4
    1  12  9  6  6
    2  37 45 33 37
    3  11 11  8 11
    4   3  0  0  2
    5   2  1  0  0
    6   0  0  0  1
    8   3  1  2  2
    9   2  2  0  2
    10  1  1  2  1
    11  1  0  0  0
    13  0  0  1  0

Then I did the following instructions

	u<-cbind(0,0,0,0)
	rt1<-rbind(t1[1:6,],u,t1[7:8,],u,t1[9,],u,u)

	rt2<-rbind(t2[1:6,],u,t2[7:10,],u,u,t2[11,])

	rt3<-rbind(t3[1:6,],u,t3[7:10,],u,u)

4) Now all my tables are 13 x 4 so I defined as matrix:

	mrt1<-matrix(rt1,nrow=13,ncol=4)
	mrt2<-matrix(rt2,nrow=13,ncol=4)
	mrt3<-matrix(rt2,nrow=13,ncol=4)

5) And then I added them:

	total<-mrt1+mrt2+mrt3
	total

      [,1] [,2] [,3] [,4]
 [1,]  130   97   83   89
 [2,]   53   55   42   46
 [3,]   33   36   36   39
 [4,]    5    1    2    3
 [5,]    5    4    1    0
 [6,]    1    1    1    3
 [7,]    0    0    0    0
 [8,]    8    6    4    4
 [9,]    6    4    1    2
[10,]    1    2    2    3
[11,]    1    1    1    1
[12,]    0    0    0    0
[13,]    0    0    1    0

which is the result I wanted.

I don't know if this is the best way to make this kind of tables, but at
least it worked well on weekend late at night :P

If someone have a better (faster) way to make them please help me.

Warm regards from Mexico.



-----Mensaje original-----
De: Petr PIKAL [mailto:petr.pikal at precheza.cz]
Enviado el: Lunes, 03 de Diciembre de 2007 02:30 a.m.
Para: rodrigueza at schwabe.com.mx
CC: r-help at r-project.org
Asunto: Re: [R] Help with tables


Hi

I am not sure but if I remember correctly I had seen similar output in
Frank Harrel's book. So you could check some function from Hmisc package,
probably summarize.

Regards

Petr
petr.pikal at precheza.cz

r-help-bounces at r-project.org napsal dne 02.12.2007 03:16:09:
,
variable
<rodrigueza at schwabe.com.mx>
ask
Respiratory
called
my
crossing
and
mention.
"Multiple
(showed
more.
http://www.R-project.org/posting-guide.html