Skip to content

Sample selection problem

1 message · Jenny Barnes

#
Hi,

Can't you do something like:

x <- c(1,1,1,1,1,1,0,0,0,0)
sample(x, 30, T)

Best Wishes,

Jenny
HTML_MESSAGE autolearn=no version=3.2.3
sIA8jEAVM1l7INcavAEUFuJk.tlFK1fXrul.GxIEMcxm_vue__YCqQXvo5CFerX5LVHjZDKx7.BqRTj0
zDdTOIevqWu2.u8JP9P2fJkBk9_vTPE.0fORnQ0Oxa9ekA--
<mailto:r-help-request at r-project.org?subject=unsubscribe>
<mailto:r-help-request at r-project.org?subject=subscribe>
BAYES_00 -4.90, FROM_ENDS_IN_NUMS 0.99)
values 0 and 1 with replacement, but with different probability for selection. 
For example 0 will be selected with probability 0.4 and 1 with 0.6. I could use 
sample function i.e. sample(c(0,1), 30, T) to get this, however here, selection 
of either 0 or 1 has equal probability here. I am looking for a function which 
can do the same thing but with different probabilities.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jennifer Barnes
PhD student: long range drought prediction 
Climate Extremes Group
Department of Space and Climate Physics
University College London
Holmbury St Mary 
Dorking, Surrey, RH5 6NT
Tel: 01483 204149
Mob: 07916 139187
Web: http://climate.mssl.ucl.ac.uk