r - Unable to store the results of a double for loop -


i quite new r , wrote double for-loop want (a block-bootstrap of index numbers block length). however, unable store in matrix print(x_sample) shows me. have tried lapply , else find here, unable solve problem myself. hope can help. many in advance

here code: x <- c(1:1060,1,2,3) x_sample <- numeric(119*4) (i in 1:3){ (j in 0:119){ idx <- sample(1:1060,1,replace=true) x_sample[(4*j+1):(4*j+4)] <- x[(idx):(idx+3)] } print(x_sample)} 

do mean this?:

values <- c(1:1060, 1, 2, 3) m <- sapply(sample(1:1060, 360, replace=true), function(idx)values[(idx):(idx+3)]) 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -