Dear Tian,

You could simply try that: table(a[,1], a[,2], a[,3])

Regards,
Sandrine Lunven

-----Message d'origine-----
De : r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] De
la part de Tian Shen
Envoyé : jeudi 9 avril 2009 09:06
À : r-help@r-project.org
Objet : [R] Create 2*3 Table in R

Dear all,
I have a matrix as follows:
a=matrix(c(1,2,3,1,2,3,1,2,3,6,5,7,7,5,7,5,6,5,"Y", "N","Y","Y","N","Y", 
"N","Y","Y"),ncol=3)
 > a
      [,1] [,2] [,3]
 [1,] "1"  "6"  "Y"
 [2,] "2"  "5"  "N"
 [3,] "3"  "7"  "Y"
 [4,] "1"  "7"  "Y"
 [5,] "2"  "5"  "N"
 [6,] "3"  "7"  "Y"
 [7,] "1"  "5"  "N"
 [8,] "2"  "6"  "Y"
 [9,] "3"  "5"  "Y"
[10,] "1"  "5"  "Y"

Here, the first two columns are considered as factors, the third columns 
are values.
I want to categorize a[,3] based on a[,1] and a[,2], ie, I want to 
create a table as:
                1       2       3
5   
        Y       1       0       1
N       1       5       0
 6    
        Y       
        ..      ..
N       ..      ..      ..
7    
        Y       ..      ..      ..
N       ..      ..      ..


I tried  the CorssTable function, but it couldn't give what I want. I 
just wonder is there any way/function that can do this job?

Thank you very much!

Cheers,
Jessie

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Ce message entrant est certifié sans virus connu.
Analyse effectuée par AVG - www.avg.fr 
Version: 8.5.285 / Base de données virale: 270.11.46/2046 - Date: 04/07/09
17:53:00

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to