[R] the dimname of a table

From: ronggui <0034058_at_fudan.edu.cn>
Date: Fri 24 Jun 2005 - 01:12:17 EST


i have a data frame(dat) which has many variables.and i use the following script to get the crosstable.

>danx2<-c("x1.1","x1.2","x1.3","x1.4","x1.5","x2","x4","x5","x6","x7","x8.1","x8.2","x8.3","x8.4","x11",
"x13","x17","x19","x20","x21")
>indep<-c("x23","x24","x25","x26","x27","x28.1","x28.2","x29")
>for (k in indep){

  for (i in danx2){

     a<-chisq.test(dat[,i],dat[,k])$p.v<=0.05
     if (a) {CrossTable(dat[,i],dat[,k],chisq=T,format="SPSS");cat(rep("=",50),"\n","\n")}
 }

  it has a little pitfall:the dimnames of table is dat[,i] and dat[,k],but i want it to be like x2,x23... is there any good way to do this?
  and in the command CrossTable(dat[,i],dat[,k],chisq=T,format="SPSS") in the loop,is there any other way to get the variable other than dat[,i] and dat[,k]?   thank you !
 

             | dat[,k] 
     dat[,i] |        1  |        2  |        3  |        4  |        5  |       10  | Row Total | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
           1 |       97  |       10  |       38  |       21  |       15  |        0  |      181  | 
             |    2.184  |    0.266  |    2.155  |    0.033  |    0.030  |      NaN  |           | 
             |   53.591% |    5.525% |   20.994% |   11.602% |    8.287% |    0.000% |   56.037% | 
             |   65.101% |   47.619% |   44.186% |   53.846% |   53.571% |      NaN% |           | 
             |   30.031% |    3.096% |   11.765% |    6.502% |    4.644% |    0.000% |           | 
-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
           2 |       29  |        5  |       27  |        4  |        5  |        0  |       70  | 
             |    0.335  |    0.044  |    3.752  |    2.345  |    0.188  |      NaN  |           | 

..........

-- 
Department of Sociology
Fudan University,Shanghai
Blog:http://sociology.yculblog.com

______________________________________________
R-help@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
Received on Fri Jun 24 01:19:17 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:59 EST