Using IF Statements on Vectors in R -


so i'm trying code fraud detection algorithm using r. have numerical value (fraudval) proportional how user committing fraud in vector. how create new column state if it's high, medium, or low, given sensitivity of 'fraudval' (i.e. if 0.6 > 'fraudval' > 0.3, it's low, if in between 0.6 , 0.8 med, , and high if it's 0.8 or higher.

here input , expected output

sensitivities are: low - 0, low - 0.3, medium - 0.6, high - 0.8

input (df):

id fraudval 1  0.4 2  0.8 3  0.2 4  0.6 

output (df):

id fraudval test 1  0.4      low 2  0.8      high 3  0.2      low 4  0.6      medium 

thanks in advance! :d

i use cut:

r> df$test <- cut(df$fraudval, c(0,.3,.6,.8,inf), +                c("very low", "low", "med", "high"), right=false) r> d   id fraudval     test 1  1      0.4      low 2  2      0.8     high 3  3      0.2 low 4  4      0.6      med 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -