[R] assignment of categorical variables to matrix/table

JS Huang js.huang at protective.com
Wed Feb 11 05:14:09 CET 2015


Hi,

  Try this with three category variables.

> A
[1] "Baby"     "Kid"      "Teenager" "Adult"    "Mature"  
> B
[1] "Male"   "Female"
> C
[1] "PST" "MST" "CST" "EST"
> expand.grid(Age=A, Sex=B, Zone=C)
        Age    Sex Zone
1      Baby   Male  PST
2       Kid   Male  PST
3  Teenager   Male  PST
4     Adult   Male  PST
5    Mature   Male  PST
6      Baby Female  PST
7       Kid Female  PST
8  Teenager Female  PST
9     Adult Female  PST
10   Mature Female  PST
11     Baby   Male  MST
12      Kid   Male  MST
13 Teenager   Male  MST
14    Adult   Male  MST
15   Mature   Male  MST
16     Baby Female  MST
17      Kid Female  MST
18 Teenager Female  MST
19    Adult Female  MST
20   Mature Female  MST
21     Baby   Male  CST
22      Kid   Male  CST
23 Teenager   Male  CST
24    Adult   Male  CST
25   Mature   Male  CST
26     Baby Female  CST
27      Kid Female  CST
28 Teenager Female  CST
29    Adult Female  CST
30   Mature Female  CST
31     Baby   Male  EST
32      Kid   Male  EST
33 Teenager   Male  EST
34    Adult   Male  EST
35   Mature   Male  EST
36     Baby Female  EST
37      Kid Female  EST
38 Teenager Female  EST
39    Adult Female  EST
40   Mature Female  EST




--
View this message in context: http://r.789695.n4.nabble.com/assignment-of-categorical-variables-to-matrix-table-tp4702981p4703071.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list