vendredi 17 février 2017

Change windirection degrees to char in R

So i have read in a csv file about weather on days. One of the variables is called winddirection(windrichting) but it is given in degrees and 0 and 990 have special meaning. I want to change the numbers to: North/south/west/east but when i used the replace funtion it changed the datatype of the whole vector to char which prevented my next replace with a range to work. So now i ended up with an if/elseif/else statement but i can't get it to work. Also i get an error condition has length >1 .. can anyone help me get this to work so i have the ranges 45-135 to east 135-225 south etc.

here is my code where mydata$DD is the variable for winddirection with over 2000 values.

windrichting <- mydata$DD 
windrichting <- if (windrichting == 990 ){
  windrichting == "Veranderlijk"
} else if (windrichting>45 && windrichting<=135){
  windrichting == "Oost"
} else if (windrichting>135 && windrichting<=225){
  windrichting == "Zuid"
} else if (windrichting>225 && windrichting <=315){
  windrichting == "West"
} else if (windrichting ==0){
  windrichting == "Windstil"
} else windrichting == "Noord"

Aucun commentaire:

Enregistrer un commentaire