2
I would like to generate nBS
reamostras for each of the N
column vectors of size n
of my matrix, and then return something like a list.
I got something similar to the one desired with the following (testing with equal values in the vector to make sure that the reamostras are from the respective columns):
v1 = c(1,3,2,4,1)
v2 = c(2,2,2,2,2)
dados = matrix(c(v1,v2),ncol = 2)
N = ncol(dados)
n = nrow(dados)
nBS <- 5
for (i in 1:N){
y = dados[,i]
lst <- lapply(1:N, function(x) matrix(sample(y,n,T), nrow = n, ncol = nBS))
}
But my exit apparently indicates that only the v2
was used in this resampling:
> lst
[[1]]
[,1] [,2] [,3] [,4] [,5]
[1,] 2 2 2 2 2
[2,] 2 2 2 2 2
[3,] 2 2 2 2 2
[4,] 2 2 2 2 2
[5,] 2 2 2 2 2
[[2]]
[,1] [,2] [,3] [,4] [,5]
[1,] 2 2 2 2 2
[2,] 2 2 2 2 2
[3,] 2 2 2 2 2
[4,] 2 2 2 2 2
[5,] 2 2 2 2 2
How do I scroll through all columns of my matrix and return nBS
reamoysters in size n
for each of my N
vectors?
Thanks in advance for the help!
Thank you so much! Working beautifully the way I need! Clear and complete answer!
– user156522