Re: [R] Which variable exist after random

From: Achim Zeileis <Achim.Zeileis_at_wu-wien.ac.at>
Date: Thu 02 Jun 2005 - 01:04:45 EST

On Wed, 1 Jun 2005 17:05:52 +0200 Sofyan Iyan wrote:

> Dear R-helper,
> How could I count only some variable was exist after running sample
> (random) function.

I'm not completely sure what you want, but maybe you want to look at table() and try print(table(x)) instead of print(x). Those levels with 0 occurences don't occur in the random sample. Z

> 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@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@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 01:55:02 2005

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