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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:17:45+00:00 2026-06-05T05:17:45+00:00

I am trying to use for to create multiple objects from for, just example

  • 0

I am trying to use for to create multiple objects from for, just example (not exact):

l_gr <- list (1:10, 11:20, 21:30)
for (i in 1:length(l_gr)){
  grp <- NULL
  grp[[i]] <- mean(l_gr[[i]])
    }

This is not what I am expecting, rather I need to output multiple objects (of different class) however the name is different with i level for example: here grp1, grp2, grp3.
Each of these object has output of the function for particular i list. Sorry for simple question.

Edits: response to provide specific example:

install.packages("onemap")
require(onemap)
data(example.out)
twopts <- rf.2pts(example.out)
all.data <- make.seq(twopts,"all") 
link_gr <- group(all.data)
link_gr$n.groups

starts the loop

  # without loop: 
# for 1
grp1 <- make.seq(link_gr, 1)
grp1.od <- order.seq(input.seq=grp1, n.init = 5,  subset.search = "twopt", 
    twopt.alg = "rcd", THRES = 3, draw.try = TRUE, wait = 1, touchdown=TRUE) 


# for 2
grp2 <- make.seq(link_gr, 2)
grp2.od <- order.seq(input.seq=grp2, n.init = 5,  subset.search = "twopt",  
   twopt.alg = "rcd", THRES = 3, draw.try = TRUE, wait = 1, touchdown=TRUE) 

same process report for 1:1:link_gr$n.groups

So I want create a for loop and output objects:

for (i in 1:link_gr$n.groups){
    grp <- NULL
  grp[i] <- make.seq(link_gr, i)
  grp[i].od <- order.seq(input.seq=grp[i], n.init = 5,  subset.search = "twopt",  
      twopt.alg = "rcd", THRES = 3, draw.try = TRUE, wait = 1, touchdown=TRUE)
    } 
  • 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-05T05:17:46+00:00Added an answer on June 5, 2026 at 5:17 am

    Note that your for loops are wrong. If you set grp <- NULL within the loop, you’ll just wipe your results variable with each iteration – probably not what you want. You need to put the variable initialisation outside the loop.

    Note, too, that I’d suggest that you are still better off using a single variable instead of multiple ones. list objects are very flexible in R and can accomodate objects of different classes. You can do

     require(onemap)
     data(example.out)
     twopts <- rf.2pts(example.out)
     all.data <- make.seq(twopts,"all") 
     link_gr <- group(all.data)
     link_gr$n.groups
    
       # initialise list outputs
     grp = list()
     grp.od = list()
     for (i in 1:2){
     grp[[i]] <- make.seq(link_gr, i)
     grp.od[[i]] <- order.seq(input.seq=grp[[i]], n.init = 5,  subset.search = "twopt", 
         twopt.alg = "rcd", THRES = 3, draw.try = TRUE, wait = 1, touchdown=TRUE) 
     }
    
     #check out output
     str(grp)
     str(grp.od)
     grp[[1]]
     grp[[2]
    

    If you must insist on using different variables, consider ?assign and ?get. Something like this will work:

     i = 1
     assign(paste("grp", i, sep = ""), grp[[1]])
     exists("grp1")
     str(get(paste("grp", i, sep = "")))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Node.js to create a zip file from an existing folder,
Trying to use Jbuilder to create some JSON views for my app, but the
i am trying to use GZipStream to create a gz file using c#. my
I am trying to use matplotlib to create a graph to reflect real time
Ok I'm stumped. I have been trying to use Simpletip to create a tooltip
I am trying to use the googlecharts gem to create some quick charts. Here
I'm trying to use a view to create an ADO.NET entity using a view.
I'm trying to use the header() function to create a redirect. I would like
I'm trying to use the Timespan class to create a start time and a
I am trying to use a factory pattern to create a QuestionTypeFactory where the

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.