samedi 21 août 2021

For loop with If/Else statements are not assigning the correct levels to the column it is referencing

Here is my code. I am trying to assign levels in a different column depending on what the numberPickOverall is. It is assigning levels, but the levels are completely wrong. I will attach an image so you can see what I mean. I have tried a hundred times but it just can not follow a simple if statement to assign the correct levels. Any advice would be appreciate or tips on what I am doing wrong.

for(i in 1:nrow(draft_raptor)){
  if(draft_raptor[i,24]==1){
    draft_raptor[i,27]<-"top pick"
    
  }
  else if(draft_raptor[i,24]>=2 &draft_raptor[i,24]<=30){
    draft_raptor[i,27]<-"top 3"
  }
  else if(draft_raptor[i,24]>=4 &draft_raptor[i,24]<=5){
    draft_raptor[i,27]<-"top 5"
  }
  else if(draft_raptor[i,24]>=6 &draft_raptor[i,24]<=10){
    draft_raptor[i,27]<-"top 10"
  }
  else if(draft_raptor[i,24]>=11 &draft_raptor[i,24]<=14){
    draft_raptor[i,27]<-"late lottery"
  }
  else if(draft_raptor[i,24]>=15 &draft_raptor[i,24]<=23){
    draft_raptor[i,27]<-"mid 1st round"
  }
  else if(draft_raptor[i,24]>=24 &draft_raptor[i,24]<=30){
    draft_raptor[i,27]<-"late first"
  }
  else if(draft_raptor[i,24]>=31 &draft_raptor[i,24]<=40){
    draft_raptor[i,27]<-"early 2nd"
  }
  else if(draft_raptor[i,24]>=41 &draft_raptor[i,24]<=50){
    draft_raptor[i,27]<-"mid 2nd"
  }
  else if(draft_raptor[i,24]>=51 &draft_raptor[i,24]<=60){
    draft_raptor[i,27]<-"late 2nd"
  }
}

Below are some of the results, as you can see, it is totally misplacing the levels and I truly have no idea why. Any help would be appreciated.


 
 
draft_level
<chr>
numberPickOverall
<int>
1   early 2nd   32      
2   early 2nd   32      
3   early 2nd   32      
4   top 3   26      
5   top 3   26      
6   top 3   26      
7   top 3   26      
8   top 3   26      
9   top 3   26      
10  top 3   26  
11  top 3   26      
12  top 3   26      
13  top 3   26      
14  top 3   26      
15  top 3   4       
16  top 3   4       
17  top 3   4       
18  top 3   4       
19  mid 2nd 49      
20  mid 2nd 49  

Aucun commentaire:

Enregistrer un commentaire