samedi 2 juin 2018

Multiple conditions generate a new wrong cloumn

I have the following data

df<-read.table(text="A1  A2      A3      BC
2       2       0       66.66666667
               2        2       2       100
               2        0       2       66.66666667
               2        2       1       83.33333333 ",h=T)

BF<- 33  
BG<-90 

When I run the following conditions, I get wrong numbers for Z, i.e., the same value.

df$Z<-with(df,ifelse(BC<BF,(40-40*(BF-BC)/BF),ifelse(BG<100,(ifelse(BC<BG,(70-(70-40)*(BG-BC)/(BG-BF)),(100-(30*(100-BC)/(100-BG))))),(100-(60*(100-BC)/(100-BF))))))

Any help to get the Z column correctly.

Aucun commentaire:

Enregistrer un commentaire