I have this code and I want sample(1:3650, 365, replace=T)
to generate the same numbers at both instances, but different values for each replication. So that for each replication i generate 365 random values and those values are used for both appending for both mydf1allt and mydf2allt, but different 365 values for each replication. Since there is correlation between them i want to capture that. This is my attempt at making a function for bivariate bootstrap. I know how to fix this with a for loop but it takes forever to run, so would be nice it could be made without.
listboot1sl = c()
listboot2sl = c()
pairbootstrap2 <- function(y) {
.GlobalEnv$listboot1sl <- replicate(10**y, rbind(listboot1sl, max(sum(mydf1allt[,2][sample(1:3650, 365, replace=T)])-17980405,0)))
.GlobalEnv$listboot2sl <- replicate(10**y, rbind(listboot2sl, max(sum(mydf2allt[,2][sample(1:3650, 365, replace=T)])-137376627,0)))
}
(mydf2allt is made out of two columns with numbers.)
This is with a foor loop doing what I want it to do without a foor loop:
pairbootstrap2 <- function(y) {
for (i in 1:10**y){
z <- sample(1:3650, 365, replace=T)
.GlobalEnv$listboot1sl <- rbind(listboot1sl, max(sum(mydf1allt[,2][z])-17980405,0))
.GlobalEnv$listboot2sl <- rbind(listboot2sl, max(sum(mydf2allt[,2][z])-137376627,0))
}
}