Skip to content
Prev 95436 / 398500 Next

random sampling problems?

On 04-Jul-06 zhijie zhang wrote:
I'm not quite sure what you are asking, but perhaps you can confirm
that it corresponds to the following, which is what you seem to mean
according to your wording.

You want an output which consists of the following:

  a random sample of 3 from the list of values of x
  an independent random sample of 3 from the list of values of y
  the list of the id values for the sampled values of x
  the list of the id values for the sampled values of y

  where the sampling is without replacement (default for "sample")

If that is the case, then

  idx<-sample(data$id,3)
  idx
# [1] 6 8 9
  idy<-sample(data$id,3)
  idy
# [1] 7 2 3
  sampx<-data$x[idx]
  sampx
# [1] 3 2 3
  sampy<-data$y[idy]
  sampy
# [1] 3 1 1
  samples<-data.frame(sampx,sampy,idx,idy)
  samples
#   sampx sampy idx idy
# 1     3     3   6   7
# 2     2     1   8   2
# 3     3     1   9   3

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 04-Jul-06                                       Time: 09:30:00
------------------------------ XFMail ------------------------------