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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:12:51+00:00 2026-06-07T19:12:51+00:00

The following is sample data and part of function I have trouble with. #

  • 0

The following is sample data and part of function I have trouble with.

# data
Gr1 <- data.frame (group = rep(1:2, each = 2001), 
position = round (c(0, cumsum (rnorm (2000, 0.05, 0.08)), 0, 
cumsum (rnorm (2000, 0.05, 0.08)))))

 Gr2 <- data.frame (group = rep(1:2, each = 2001), 
 position = round (c(0, cumsum (rnorm (2000, 0.05, 0.08)), 0, 
  cumsum (rnorm (2000, 0.04, 0.08)))))

 Gr3 <- data.frame (group = rep(1:2, each = 2001), 
position = round (c(0, cumsum (rnorm (2000, 0.05, 0.08)), 0, 
 cumsum (rnorm (2000, 0.05, 0.08)))))

 groupobs = list(Gr1, Gr2, Gr3)
 grnames = c("A", "B", "C")
 spacing = c(0, 0.1, 0.3)


    # for loop 

    for (i in 1:length(groupobs)){
     groupobs[i]$sgrp <- grnames[i]
     groupobs[i]$y <-  groupobs[i]$group + spacing[i]
    }

    # binding of list components
    mydf <- data.frame (rbind (groupobs)

How can I achieve this ?

Edit: With above loop, I want to achieve the following manual process. I want to automate n number of dataframe, so that I do not need to write a lengthy steps:

Please note that each of dataframes in this have same name of variables. For each component dataframe I want perform the following tasks. If I do it without looping:

# for first dataframe with in list 
Gr1$sgrp <- grnames[1]
Gr1$y <- Gr1$group + spacing[1]

# for second dataframe in the list
Gr2$sgrp <- grnames[2]
Gr2$y <- Gr1$group + spacing[2]

# for third dataframe in the list
Gr3$sgrp <- grnames[3]
Gr3$y <- Gr1$group + spacing[3]

mydf <- data.frame (rbind (Gr1, Gr2, Gr3))
  • 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-07T19:12:52+00:00Added an answer on June 7, 2026 at 7:12 pm

    I maybe be way off here but

    mydf<-mapply(function(a,b,c){a$sgrp<-b;a$y<-c;a},groupobs,grnames,spacing,SIMPLIFY = F)
    mydf<-do.call("rbind",mydf)
    > str(mydf)
    'data.frame':   12006 obs. of  4 variables:
     $ group   : int  1 1 1 1 1 1 1 1 1 1 ...
     $ position: num  0 0 0 0 0 0 0 0 0 1 ...
     $ sgrp    : chr  "A" "A" "A" "A" ...
     $ y       : num  0 0 0 0 0 0 0 0 0 0 ...
    

    might be what you are after………….

    EDIT: changed to hopefully produce dataframe

    thanks to @jon

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I have the following sample of data to insert into tables(from parent to child,
1I have the following two tables (sample data) and need to be able to
I have data in a table that looks like the following sample data: varchar(20)
How can you use the following sample data either with a foreach or while
I'm using XOM with the following sample data: Element root = cleanDoc.getRootElement(); //find all
For my question lets consider the following sample table data: ProductID    ProductName    Price   Category 1                Apple                 5.00       Fruits
Following is the sample data. I need to make 3 copies of this data
Assume we have the following data: H_T = [36 66 21 65 52 67
I have the following classes: Defect - represents a type of data that can

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.