loop

  1. M

    Create loop for Monte Carlo Simulation

    Hi I have some trouble writing out a monte carlo simulation properly. I assign variables for the process before the steps. The first step is assigning variable j = j + 1 Second step i draw three random numbers from a U(0,1) dist. u1, u2 and u3. Third step is a long if formula. It...
  2. M

    how to reshape the matrix with or without do loop?

    Dear All, I need to reshape below matrix with or without do loop: Below is my question: fd=read.table(header=TRUE, text=" X1 X2 X3 X4 X5 X6 18.25766 123.9019 151.4487 34.1252 196.6713 231.2289 16.89285 121.7344 146.5685 60.4828 299.1966 346.6185...
  3. D

    Writing a mean loop.. (literally)

    So my test data looks like this: structure(list(day = c(1L, 1L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L ), Left = c(0.25, 0.33, 0, 0, 0.25, 0.33, 0.5, 0.33, 0.5, 0), Left1 = c(NA, NA, 0, 0.5, 0.25, 0.33, 0.1, 0.33, 0.5, 0), Middle = c(0, 0, 0.3, 0, 0.25, 0, 0.3, 0.33, 0, 0), Right = c(0.25...
  4. R

    Observations with probability in R

    Hello, please assist me in answering the following question involving R code and statistics. Loop through CoinTosses<-matrix(nrow=5000,ncol=20) to simulate for each column, 50 coin tosses where a toss has a probability of heads, from 0.05 to 1 probability in each column respectively. Coin...
  5. S

    Entering values into a matrix from a loop command

    I have created a loop to generate a counter variable values that will then be entered into an OUTPUT matrix. Everything except for 1 line seems to be working. The line is here: matrix OUTPUT[`i', `j']=counter *STATA writes: counter not found. But then I write: display...
  6. C

    Stochastic differential equation data simulation

    I have written the following which takes a bit of time to run (which is to be expected) but I am just wondering if I could speed up the time it takes if I make my code more efficient. Any help with this would be much appreciated! require(deSolve) S <- c(y=.1, b=.2, o=.7) times <-...
  7. G

    sum in column by date

    Hi all, I have a small problem which is holding me back and I cannot figure it out. In a dataset I need to calculate the sum of variable "value" and put the result in a new variable "result". The problem is, that the calculation needs to be done by id and date. Every id can have multiple...