transfrom

Coordinator
May 15, 2014 at 10:57 PM
extract_feature<-function(x)
{

ret_vec=list()
length(ret_vec)<-22

y=x[x$record_type==0,]

ret_vec[1:15]=x


if(ret_vec[2]==0)
     { ret_vec[16]=ret_vec[2]}
else if (rec_vec[2]==1)
     { ret_vec[16]=ret_vec[9]}
else
     { ret_vec[16]=ret_vec[2]} 
if (ret_vec[3]==0)
     { ret_vec[17]=ret_vec[3]}
else
     { ret_vec[17]=ret_vec[10]}
if (ret_vec[4]==1)
     { ret_vec[18]=ret_vec[4]}
else if (ret_vec[4]==2)
     { ret_vec[18]=ret_vec[4]}
else if (ret_vec[4]==3)
     { ret_vec[18]=ret_vec[11]}
else
     { ret_vec[18]=ret_vec[4]}
if (ret_vec[5]==0)
     { ret_vec[19]=ret_vec[12]}
else if (ret_vec[5]==1)
     { ret_vec[19]=ret_vec[12]}
else
     { ret_vec[19]=ret_vec[5]} 
if (rec_vec[6]==0)
     { rec_vec[20]=rec[13]}
else
     { rec_vec[20]=rec[6]}
if (rec_vec[7]==1)
     { rec_vec[21]=rec[7]}
else if (rec_vec[7]==2)
     { rec_vec[21]=rec[14]}
else if(rec_vec[7]==3)
     { rec_vec[21]=rec[14]}
else
     { rec_vec[21]=rec[7]}
if(rec_vec[8]==1)
     { rec_vec[22]=rec[15]}
else if (ret_vec[8]==2)
     { rec_vec[22]=rec[15]}
else if (ret_vet[8]==3)
     { rec_vet[22]=rec[8]}
else
     { rec_vet[22]=rec[8]}
print(x["customer_ID"])
return(ret_vec)
}


train=read.csv("C:/Code/R/Policies/result10.csv")
features_train=do.call("rbind",as.list(by(train,train$customer_ID,extract_feature)))
colnames(features_train)<-c("X",
                        "A_Last","B_Last","C_Last","D_Last","E_Last","F_Last","G_Last",
                        "A","B","C","D","E","F","G",
                        "A1","B1","C1","D1","E1","F1","G1")
write.csv(features_train,"C:/Code/R/Policies/result11.csv")