[R] Which variable exist after random

Sofyan Iyan sofyan.iyan at gmail.com
Wed Jun 1 18:06:27 CEST 2005


Thanks for your help.
How about if I count all. This below I have fixed my code which used
table. I need the result:

    Game Internet    Money    Paper     Time 
       4        1              1            4        0 

Regards, Sofyan

> testx <- factor(c("Game","Paper","Internet","Time","Money"))
>     for(i in 1:2) {
+         x <- sample(testx,replace=TRUE)
+         print(x)
+         print(table(x))
+     }
[1] Game  Paper Game  Paper Paper
Levels: Game Internet Money Paper Time
x
    Game Internet    Money    Paper     Time 
       2        0        0        3        0 
[1] Game     Game     Internet Paper    Money   
Levels: Game Internet Money Paper Time
x
    Game Internet    Money    Paper     Time 
       2        1        1        1        0 
> 


On 6/1/05, TEMPL Matthias <Matthias.Templ at statistik.gv.at> wrote:
> > Dear R-helper,
> > How could I count only some variable was exist after running sample
> > (random) function.
> 
> Or is this what you want?
> 
> Tab <- table(sample(testx, replace=TRUE))
> Tab[ Tab > 0 ]
>




More information about the R-help mailing list