mardi 28 novembre 2017

R sampling questions

I'm looking to create a couple types of sample variables. I have two questions with sampling.

  1. Is there a way to sample and give a percentage of the split between choices? e.g. sample(c("Hold", "Pass"), 10000, replace = TRUE) will give an even chance to sample the 10000 observations between Hold and Pass, but what if I want a 25/75 split?

I could do sample(c(rep("Hold", 25), rep("Pass", 75)), 1000, replace = TRUE) but is there a better way to do this?

  1. I would like to create a skewed sample, or rnorm, say for example between the numbers 1000, and 100,000. But I want it to skew right, so that most of the values are around the 1000-10000 mark, and then a smaller and smaller as we approach 100,000.

I have found some documentation doing the following, and have played around with it to get a distribution that skews left:

rsn(n=45000, xi=1000, omega=20000, alpha=20, tau=0, dp=NULL)

I would like to understand more about how this works or if there is another way to do it.

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire