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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:22:40+00:00 2026-06-18T04:22:40+00:00

I’m to get the vector simualted_results to take values returned by simulation, which produced

  • 0

I’m to get the vector simualted_results to take values returned by “simulation,” which produced a vector of varying length depending on the iteration.

Initially I have this code which works, but is very slow:

simulated_results<-NULL
while(as.numeric(Sys.time())-start<duration){
  simulated_results <- cbind(simulated_results,simulation(J,4* (length(J)^2),0.0007,duration,start))

 }

But its very slow so I modified it:

start<-as.numeric(Sys.time())
duration<-10
simulated_results<-NULL
simulated_results <- cbind(simulated_results,
                       replicate(n=10000,expr=(while(as.numeric(Sys.time())-start<duration)
                         {simulation(J,4*(length(J)^2),0.0007,duration,start)})))

Now with the new code, my problem is that despite everything running, I cant get the results of simulation to be passed to simualted_results, instead simualted_results jsut takes on a column vector of NULL values
I get no error messages

I would greatly appreciate any help!!

for reference the simulation code is:

iter<-as.numeric(Sys.getenv("PBS_ARRAY_INDEX"))

if(iter <= 40){J<-1:500
}else if(iter <= 80){J<-1:1500
}else if(iter <= 120){J<-1:2500
}else if(iter <= 160){J<-1:5000}

set.seed(iter)
simulation <- function(J,gens,v=0.1,duration,start){

  species_richness <- function(J){
    a <- table(J)
    return(NROW(a))
  }

  start<-as.numeric(Sys.time())

  species_richness_output <- rep(NA,gens)
  for(rep in 1:gens){

    if (as.numeric(Sys.time())-start<duration){

      index1 <- sample(1:length(J),1)

      if(runif(1,0,1) < v){
        J[index1] <- (rep+100)
      } 
      else{
        index2 <- sample(1:length(J),1)
        while(index1==index2) {
          index2 <- sample(1:length(J),1)
        }
        J[index1] <- J[index2]
      }
      species_richness_output[rep] <- species_richness(J)} else break
  }

  species_abundance <- function(J){
    a <- table(J)
    return(a)
  }

  abuntable <- species_abundance(J)

  octaves <- function(abuntable)
  {
    oct<-rep(0,floor(log2(length(J))+1))

    for(i in 1:length(abuntable)){
      oct2 <- floor(log2(abuntable[i])+1)
      oct[oct2] <- oct[oct2]+1
    }

    return(oct)
  }   

  octaves(abuntable)
}
  • 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-18T04:22:41+00:00Added an answer on June 18, 2026 at 4:22 am

    I agree with @Nathan G, but something did catch my attention: You are trying to cbind two things that cannot be bound together, since they have different dimensions. We don’t know what kind of data type your simulation function returns, but it clearly is not NULL. Consider this:

    df1 <- NULL
    df2 <- data.frame(x = 1:10, y = 11:20)
    cbind(df1, df2)
    cbind(df2, df1)
    

    Both cbind statements give errors. Do you get an error? If this is what’s going on, you should initialize simulated_results not as NULL but as an empty version of whatever the function simulation returns.

    EDIT

    iter = 10
    set.seed(iter)
    J <- 1:1500
    # critical to preallocate the list size for speed
    res <- vector("list", iter)
    for (i in 1: iter) {
        res[[i]] <- simulation(J,4* (length(J)^2),0.0007,duration = 10,start)
    }
    str(res)
    res[[1]]
    

    Now I don’t think I’m using this quite the way you ultimately intend, but perhaps this will give you enough to get to what you actually want.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to run a str_replace or preg_replace which looks for certain words
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have an array which has BIG numbers and small numbers in it. I
I'm trying to select an H1 element which is the second-child in its group
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.