I have a vector from 1 to 10 which I divided into blocks of size 2 each and then resample the blocks but I am not happy with the result arrangement in r. the below r code demonstrates my experience:
ts <- 1:10 # generate a number from 1 to 10
bs <- 2 # let block size equals 2
nb <- length(ts) / bs # number of blocks
blk <- split(ts, rep(1:nb, each=bs)) # split the generated numbers into "blk"
res<-sample(blk, replace=T, 20) # resample the blk 20 times with replacement
res # gives me the below result
#$`5`
#[1] 9 10
#$`5`
#[1] 9 10
#$`5`
#[1] 9 10
#$`3`
#[1] 5 6
#$`1`
#[1] 1 2
#$`2`
#[1] 3 4
#$`5`
#[1] 9 10
#$`1`
#[1] 1 2
#$`1`
#[1] 1 2
#$`1`
#[1] 1 2
#$`4`
#[1] 7 8
#$`4`
#[1] 7 8
#$`4`
#[1] 7 8
#$`4`
#[1] 7 8
#$`4`
#[1] 7 8
#$`3`
#[1] 5 6
#$`2`
#[1] 3 4
#$`1`
#[1] 1 2
#$`1`
#[1] 1 2
#$`1`
#[1] 1 2
I rather want the result like:
(9,10,9,10,9,10,5,6,1,2,3,4,9,10,1,2,1,2,1,2,7,8,7,8,7,8,7,8,7,8,5,6,3,4,1,2,1,2,1,2)
such that I can call "res" as a univariate and I should be able to write the result into either one line or one column .csv file like this:
write.csv(res, "resamples.csv")
Aucun commentaire:
Enregistrer un commentaire