Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:18:32+00:00 2026-05-22T01:18:32+00:00

I have a vector of ~100k length, with values between 0 and 1 representing

  • 0

I have a vector of ~100k length, with values between 0 and 1 representing habitat suitability at geographic locations. While some of the values are very small, many of them are 0.9 etc, so the sum is much greater than one.

I would like to generate 1000 random samples of locations, each sample having length 6 (without replacement), with the probability that a location is chosen being weighted by the value of the vector at that location.

Dummy data below. Any ideas?

mylocs = letters[1:10]
myprobs = c(0.1,NA,0.01,0.2,0.6,NA,0.001,0.03,0.9,NA)
mydata = data.frame(mylocs,myprobs)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:18:33+00:00Added an answer on May 22, 2026 at 1:18 am

    I’m a bit confused with your question, so here are two possible answers.

    If you want you want to sample 1000 groups of six values, where groups can share values, then:

    locs = letters[1:15]
    probs = c(0.1,NA,0.01,0.2,0.6,NA,0.001,0.03,0.9,NA, 0.1, 0.1, 0.1, 0.1, 0.1)
    mydata = data.frame(locs,probs)
    
    d = na.omit(mydata)
    replicate(1000, sample(d$locs, size=6, prob=d$probs, replace=F))
    

    If groups shouldn’t share values, then just do:

    ## Change the "2" to 1000 in the real data set
    s = sample(d$locs, size=6*2, prob=d$probs, replace=F)
    matrix(s, ncol=6)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have vector with values between 1 and N > 1 . Some values
I have a vector containing the values 0, 1, 2 and 3. What I
I have Vector class, representing a 3D point, written as follows in Vector.h :
I have a vector object: std::vector<std::vector<MyClass>> _matrix; It is 2d array with some data.
I have vector<string> data ; // I hold some usernames in it In that
I have 2 input variables: a vector of p-values ( p ) with N
I have a very large multidimensional vector that changes in size all the time.
I have some vector of elements passed to a function and I want to
I have a vector containing integer values, which I wish to sum. However, it's
I have a vector<string> vectorStrings with values: ta, bc, ac, st, cer, cda .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.