wanr@ucalgary.ca
2004-Sep-08 21:23 UTC
[R] How to draw an observation uniformly from a given dataset?
Hi all, I have two questions stated below: 1. How to draw an observation uniformly from a given data? For example, I have a dataset (or dataframe) with 10 observations (with a set of variables) and I want to "uniformly" select an observation from this given dataset, that is, the probability of selecting each observation is 1/10. 2. How to do this "combinations"? source vector = (1,2) the length of the target vector = 3 My expected outputs should be: 111, 112, 121, 122, 211, 212, 221, 222. However, the output from the function of combinations() is only 111, 112, 122, 222. I can not even use the function permutations() because the length of the target vector is larger than the lengthe of the source vector. Could anybody tell me how to get my expected results? Thank you in advance. Rui
David Forrest
2004-Sep-08 21:32 UTC
[R] How to draw an observation uniformly from a given dataset?
On Wed, 8 Sep 2004 wanr at ucalgary.ca wrote:> Hi all, > > I have two questions stated below: > > 1. How to draw an observation uniformly from a given data? > > For example, I have a dataset (or dataframe) with 10 observations (with a > set of variables) and I want to "uniformly" select an observation from this > given dataset, that is, the probability of selecting each observation is > 1/10.sample(1:10,3,replace=TRUE)> > 2. How to do this "combinations"? > > source vector = (1,2) > the length of the target vector = 3 > > My expected outputs should be: > 111, 112, 121, 122, 211, 212, 221, 222.sample(c(1,2),3,replace=TRUE) Dave -- Dave Forrest drf at vims.edu (804)684-7900w drf5n at maplepark.com (804)642-0662h http://maplepark.com/~drf5n/
Roger D. Peng
2004-Sep-08 21:35 UTC
[R] How to draw an observation uniformly from a given dataset?
wanr at ucalgary.ca wrote:> Hi all, > > I have two questions stated below: > > 1. How to draw an observation uniformly from a given data? > > For example, I have a dataset (or dataframe) with 10 observations (with a > set of variables) and I want to "uniformly" select an observation from this > given dataset, that is, the probability of selecting each observation is > 1/10.Sample the indices, as in idx <- sample(1:10, 1) data[idx, ]> 2. How to do this "combinations"? > > source vector = (1,2) > the length of the target vector = 3 > > My expected outputs should be: > 111, 112, 121, 122, 211, 212, 221, 222. > > However, the output from the function of combinations() is only 111, 112, > 122, 222. I can not even use the function permutations() because the length > of the target vector is larger than the lengthe of the source vector. > Could anybody tell me how to get my expected results? > > Thank you in advance. > > Rui > > ______________________________________________ > 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 >