[R] Automatically simulates random numbers (not general) in R?

Thevaraja, Mayooran M@Thev@r@j@ @end|ng |rom m@@@ey@@c@nz
Fri Jun 7 02:00:03 CEST 2019


Hello Guys!

         I am wondering about below function which automatically simulates random numbers - given below that manual calculation too. Anyone help me to fix that error. I got that error "object of type 'closure' is not subsettable" So Do you have any ideas?



Regards

Mayooran



#########Manual calculation##########

N <- 1e7

n <- 8

indx <- 1:N

start1 <- sort(sample(indx,1))



start2 <- sort(sample(start1+1,1))

start3 <- sort(sample(start2+1,1))

start4 <- sort(sample(start3+1,1))

start5 <- sort(sample(start4+1,1))

start6 <- sort(sample(start5+1,1))

start7 <- sort(sample(start6+1,1))

start8 <- sort(sample(start7+1,1))



start1

start2

start3

start4

start5

start6

start7

start8

###########Common function#############

start<-function(n){

  indx <- 1:N

  for (i in 1:n) {

    if (i<2) {

  start[i] <- sort(sample(indx,1))

} else {

  start[i] <- sort(sample(start[i-1]+1,1))

}

  }

}



start(8)


	[[alternative HTML version deleted]]



More information about the R-help mailing list