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 8988167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:57:38+00:00 2026-06-15T21:57:38+00:00

I have the following list1 and list2 : df1 <- data.frame(x=(1:3),Q=(3:5)) df2 <- data.frame(x=(1:3),Q=(3:5))

  • 0

I have the following list1 and list2:

df1   <- data.frame(x=(1:3),Q=(3:5))
df2   <- data.frame(x=(1:3),Q=(3:5))
df3   <- data.frame(x=(1:3),Q=(3:5))
list1 <- list(df1,df2,df3)
list2 <- list(2,3,6)

I want to sample randomly from Q in each list1 element according to the corresponding value in
list2

So I would sample from Q 2 times for the first pair of list elements.

So far I have managed:

df1   <- data.frame(x=(1:3),Q=(3:5))
z <- 2
sapply(1:z,function(i) sample(df1$Q,1))

but I am struggling at trying to mapply this across both all pairs of elements in both lists.

  • 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-06-15T21:57:39+00:00Added an answer on June 15, 2026 at 9:57 pm

    Here’s a mapply approach:

    mapply(function(x, y) sample(x[["Q"]], y, replace = TRUE), list1, list2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following list created from a sorted csv list1 = sorted(csv1, key=operator.itemgetter(1))
I have the following list of time zones that a user can choose from,
Let's say I have 2 following lists: list1 = [1,1,1,1] list2 = [3,3,3,3] I
Please see my following code snippet. @Transactional public void saveMembersService(List<Member> list1, List<Member> list2) {
Say I have the following two lists/numpy arrays: List1 = [[1,2,3,4], [10,11,12], ...] List2
Suppose you have a data frame with the following structure: df <- data.frame(a=c(1,2,3,4), b=c(job1;job2,
I have 2 list: List1 = [1,2,3]. List2 = [asd, sda, dsa]. How can
Let's say I have the following: LinkedList<int> list1 = new LinkedList<int>(); LinkedList<int> list2 =
I have the following code: List<byte[]> list1 = new List<byte[]>(); list1.Add(new byte[] { 0x41,
I have 2 list: List1: ID 1 2 3 List2: ID Name 1 Jason

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.