lundi 19 février 2018

if else condition: error & failure

Brazil_data$chain_class<-  if (Brazil_data$selling_areain_squaredmeters >= 2500) { 
    Brazil_data$chain_class=="Hyper"
} else if 
(Brazil_data$selling_areain_squaredmeters >=1000 & Brazil_data$selling_areain_squaredmeters<2500 ) {
    Brazil_data$chain_class=="Super"
} else if 
(Brazil_data$selling_areain_squaredmeters >=400 & Brazil_data$selling_areain_squaredmeters<1000) {
    Brazil_data$chain_class=="Neighbour"}
 else 
{ Brazil_data$chain_class =="Superette"}

This is throwing an error :

Error in `$<-.data.frame`(`*tmp*`, chain_class, value = logical(0)) : 
  replacement has 0 rows, data has 17603
In addition: Warning messages:
1: In if (Brazil_data$selling_areain_squaredmeters >= 2500) { :
  the condition has length > 1 and only the first element will be used
2: In if (Brazil_data$selling_areain_squaredmeters >= 1000 & Brazil_data$selling_areain_squaredmeters <  :
  the condition has length > 1 and only the first element will be used
3: In if (Brazil_data$selling_areain_squaredmeters >= 400 & Brazil_data$selling_areain_squaredmeters <  :
  the condition has length > 1 and only the first element will be used
>  else 
Error: unexpected 'else' in " else"
> { Brazil_data$chain_class =="Superette"}
logical(0)

kindly suggest some solutions.

Aucun commentaire:

Enregistrer un commentaire