vendredi 19 novembre 2021

RStudio: Use for-loop and if function to create a new vector?

I want to do the following operation with the code: I want to get a sample of n = 30 out of a given normal distribution and calculate the mean of each sample. (until this step my function works without any problem). After that I want to create a new vector with yes or no , dependent on if the mean is in a certain range or not. Sadly the code does notconduct this step. I always get a vector with 13 elements,but there should be 500. What is the problem? Where is my mistake?

o = 13
u = 7
d = c()
for (i in 1:500){
  i = rnorm(30,mean = 10,sd = 6.04)
  i = mean(i)
  if (i <= o & i >=u) {d[i]=("Yes")
  } else {d[i]=("No")}
  
}

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire