This is my code and I will explain after you read my code.
#Start of my Code#
test1<-function(c,x){
high=0
low=0
samp=NULL
samp=sample(c,x)
for(i in 1:x){
if(samp[i]>1){high=high+1}
else if (samp[i]<0){low=low+1}}
c(high,low,mean(samp),var(samp),samp)
}
sim1 <-function(c,x){
replicate(nsim,{test1(c,x)})}
size=10
a<-sim1(overall,size)
listnormwor=NULL
countnormwor=0
meannormwor=NULL
for(i in 0:nsim-1){
**if (a[1+(size+4)*i]+a[2+(size+4)*i]==0)**{
countnormwor=countnormwor +1
for (z in 5:(size+4)){
listnormwor=c(listnormwor, a[z+(size+4)*i])}
meannormwor=c(meannormwor,a[3+(size+4)*i])}
}
countnormwor
mean(meannormwor)
var(listnormwor)
Simply, I want to say if there are no outliers (indicated as '0' in first and second value of every 14 data points), count it into a normal bucket and keep its values to calculate variance and mean later.
But the problem is that, it generates all values from a and at the very end, it provides actual values I want.
For example, it must satisfy length(listnormwor) = 10 * countnormwor
But it gives me a ridiculous amount of data and When I play around with the if statement, it says "missing value where TRUE/FALSE needed."
It's urgent. please help me~!
Aucun commentaire:
Enregistrer un commentaire