[R] combination which limited
Marc Schwartz
MSchwartz at mn.rr.com
Sat Jun 11 20:56:48 CEST 2005
On Sat, 2005-06-11 at 20:44 +0200, Muhammad Subianto wrote:
> Dear R-helpers,
> I am learning about combination in R.
> I want to combination all of
> possible variable but it limited.
> I am sorry I could not explain exactly.
> For usefull I give an example
> interface <- c("usb","fireware","infra","bluetooth")
> screen <- c("lcd","cube")
> computer <- c("pc","server","laptop")
> available <- c("yes","no")
>
> What the result I need, something like this below,
> usb lcd pc yes
> fireware lcd pc yes
> infra lcd pc yes
> bluetooth lcd pc yes
> usb cube pc yes
> usb lcd server yes
> usb lcd laptop yes
> usb lcd pc no
>
> How can I do that?
> I was wondering if someone can help me.
> Thanks you for your time and best regards,
> Muhammad Subianto
Use:
> expand.grid(interface, screen, computer, available)
Var1 Var2 Var3 Var4
1 usb lcd pc yes
2 fireware lcd pc yes
3 infra lcd pc yes
4 bluetooth lcd pc yes
5 usb cube pc yes
6 fireware cube pc yes
7 infra cube pc yes
8 bluetooth cube pc yes
9 usb lcd server yes
10 fireware lcd server yes
11 infra lcd server yes
12 bluetooth lcd server yes
13 usb cube server yes
14 fireware cube server yes
15 infra cube server yes
16 bluetooth cube server yes
17 usb lcd laptop yes
18 fireware lcd laptop yes
19 infra lcd laptop yes
20 bluetooth lcd laptop yes
21 usb cube laptop yes
22 fireware cube laptop yes
23 infra cube laptop yes
24 bluetooth cube laptop yes
25 usb lcd pc no
26 fireware lcd pc no
27 infra lcd pc no
28 bluetooth lcd pc no
29 usb cube pc no
30 fireware cube pc no
31 infra cube pc no
32 bluetooth cube pc no
33 usb lcd server no
34 fireware lcd server no
35 infra lcd server no
36 bluetooth lcd server no
37 usb cube server no
38 fireware cube server no
39 infra cube server no
40 bluetooth cube server no
41 usb lcd laptop no
42 fireware lcd laptop no
43 infra lcd laptop no
44 bluetooth lcd laptop no
45 usb cube laptop no
46 fireware cube laptop no
47 infra cube laptop no
48 bluetooth cube laptop no
See ?expand.grid for more information.
Using:
> help.search("combinations")
would guide you to that function based upon a keyword search.
HTH,
Marc Schwartz
More information about the R-help
mailing list