4
I’m a beginner in R. I’m trying to do a function to generate as many samples as possible without repeating size 4 taken from the same vector. I tried to loop the for, but I can’t do the whole thing. The vector I want to take the samples from follows below and the function I did too:
y<-c(1,2,4,4,7,7,7,8)
espaco_amostral<-function(x,n){
set.seed(360)
for(i in x){
amostra<-sample(x,n,replace=F)
}
matrix(amostra,,n)
}
espaco_amostral(y,4)
The idea is that the various samples stay in the matrix lines.
What does it mean to "generate as many size 4 samples taken from the same vector as possible"? This number is infinite because given the vector
c(1,2,4,4,7,7,7,8)
from your example, I can generate the samples1, 1, 1, 1
,1, 1, 1, 1
,1, 1, 1, 1
... and so on, no limit. They all have size 4. Do the samples have to be unique? Can they have repeated values? You need to define your problem a little better.– Marcus Nunes
I forgot to say it would be repeating samples. In case it would be all size four samples that can be taken from the vector without repeating. For example, using another vector x<-(1,2,3,4), the two possible size samples without replacement are: (1,2), (1,3), (1,4), (2,3), (2,4), (3,4). I was able to clarify?
– Danielle
Yes, now it’s clear. I gave a possible solution to the problem just below.
– Marcus Nunes
Thanks, helped!
– Danielle
It’s great to know that my response has helped you in some way. So consider vote and accept the answer, so that in the future other people who experience the same problem have a reference to solve it.
– Marcus Nunes