[R] combination which limited
Muhammad Subianto
subianto at gmail.com
Sun Jun 12 10:48:19 CEST 2005
Dear All,
Many thanks to Marc Schwartz and Gabor Grothendieck who have explained
me about using expand.grid function and clearly explain how to use
JGR.
> dd <- expand.grid(interface = interface, screen = screen,
> computer = computer, available = available)
>
> There are several possibilities now:
>
> 1. you could list out dd on the console and note the number of the
> rows you want to keep:
>
> idx <- c(1,5,7)
> dd2 <- dd[,idx]
>
I like a possible no. 1, because I can use and explore with my hand,
> idx <- c(1:5,9,17,25)
> dd2 <- dd[idx,]
> dd2
interface screen computer available
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
9 usb lcd server yes
17 usb lcd laptop yes
25 usb lcd pc no
>
Regards,
Muhammad Subianto
Notepad, Copy and Paste are my best friend to use R.2.1.0 on windows 2000
On 6/11/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> On 6/11/05, Marc Schwartz <MSchwartz at mn.rr.com> wrote:
> > 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.
> >
>
>
> After you do the above you will still want to cut it down to just
> the rows you need.
>
> As expained, use expand.grid. Let's assume you used this statement:
>
> dd <- expand.grid(interface = interface, screen = screen,
> computer = computer, available = available)
>
> There are several possibilities now:
>
> 1. you could list out dd on the console and note the number of the
> rows you want to keep:
>
> idx <- c(1,5,7)
> dd2 <- dd[,idx]
>
> or if you want most of them it may be easier to record which ones
> you do not want:
>
> ndix <- c(2,4,7)
> dd2 <- dd[,-ndix]
>
> 2. Another possibility is to export it to a spreadsheet and visually
> delete the rows you don't want.
>
> 3. A third possibility is to install JGR (which is a free Java GUI
> front end to R).
> First download and install JGR from: http://stats.math.uni-augsburg.de/JGR/
> In JGR (I am using Windows and its possible that the instructions vary
> slightly on other platforms):
>
> 1. create dd as explained
> 2. bring up the object browser using the menu Tools | Object Browser
> or just ctrl-B
> 3. Select dd from the object browser
> 4. This will put you into a spreadsheet in which you can select the
> rows you want
> to delete (hold down ctrl for the 2nd and subsequent selection to have a
> non-contiguous multi-row selection).
> 5. Select Tools | Remove Rows
> 6. Click on Apply in the lower right of the spreadsheet.
>
>
> 7. Click on X on the upper right of the spreadsheet.
>
> the menu entry Tools | Remove Rows.
>
More information about the R-help
mailing list