Re: [R] Which variable exist after random

From: Sofyan Iyan <sofyan.iyan_at_gmail.com>
Date: Thu 02 Jun 2005 - 02:06:27 EST

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@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 ]
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 02 02:22:48 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:20 EST