[R] Which variable exist after random

Liaw, Andy andy_liaw at merck.com
Wed Jun 1 17:46:24 CEST 2005


Or perhaps

> f <- factor(letters[1:2], levels=letters[1:3])
> f
[1] a b
Levels: a b c
> levels(f[, drop=TRUE])
[1] "a" "b"

Andy

> From: TEMPL Matthias
> 
> > 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 ]
> 
> > For example,
> > 
> > > testx <- factor(c("Game","Paper","Internet","Time","Money"))
> > >    for(i in 1:2) {
> > +        x <- sample(testx,replace=TRUE)
> > +        print(x)
> > +    }
> > [1] Money    Money    Time     Internet Time    
> > Levels: Game Internet Money Paper Time
> > [1] Time  Money Game  Money Money
> > Levels: Game Internet Money Paper Time
> > > 
> > 
> > The result above Game, Internet, Money, and Time only exist 
> > and "Paper" was missing. Best, Sofyan
> > 
> > ______________________________________________
> > R-help at 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
> >
> 
> ______________________________________________
> R-help at 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
> 
> 
>




More information about the R-help mailing list