Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the for loop with function needing for a string field?

I am using the smbinning R package to compute the variables information value included in my dataset.

The function smbinning() is pretty simple and it has to be used as follows:

result = smbinning(df= dataframe, y= "target_variable", x="characteristic_variable", p = 0.05)

So, df is the dataset you want to analyse, y the target variable and x is the variable of which you want to compute the information value statistics; I enumerate all the characteristic variables as z1, z2, ... z417 to be able to use a for loop to mechanize all the analysis process.

I tried to use the following for loop:

for (i in 1:417) {
 result = smbinning(df=DATA, y = "FLAG", x = "DATA[,i]", p=0.05)
  }

in order to be able to compute the information value for each variable corresponding to i column of the dataframe.

The DATA class is "data.frame" while the resultone is "character".

So, my question is how to compute the information value of each variable and store that in the object denominated result?

Thanks! Any help will be appreciated!

like image 732
Quantopik Avatar asked Feb 06 '16 16:02

Quantopik


1 Answers

No sample data is provided I can only hazard a guess that the following will work:

results_list = list()    
for (i in 1:417) {
    current_var = paste0('z', i)
    current_result = smbinning(df=DATA, y = "FLAG", x = current_var, p=0.05)
    results_list[i] = current_result$iv
}
like image 191
Tchotchke Avatar answered Sep 20 '22 08:09

Tchotchke