After I prepare my data base as shown in the code below, I tried to split the data into training and testing. So I uesd createDataPartition function to do this.
My R scripts in c#:
// the data base
DataFrame BASE = engine.Evaluate("BASE<-data.frame(Type_peau,PEAU_CORPS,SENSIBILITE,IMPERFECTIONS,BRILLANCE,GRAIN_PEAU,RIDES_VISAGE,ALLERGIES,MAINS,INTERET_ALIM_NATURELLE,INTERET_ORIGINE_GEO,INTERET_VACANCES,INTERET_COMPOSITION,INT_AGE,priorite2,priorite1,MILRES,Profil_Select,Age,Nbre_gift,Achat_client)").AsDataFrame();
// Converting categorical variables into quantitatives
engine.Evaluate("must_convert<-sapply(BASE,is.factor)").AsExpression();
engine.Evaluate("M2<-sapply(BASE[,must_convert],unclass)").AsExpression();
engine.Evaluate("out<-cbind(BASE[,!must_convert],M2)").AsExpression();
engine.Evaluate("out=unlist(lapply(out,as.numeric))").AsExpression();
engine.Evaluate("out=as.data.frame(out)").AsExpression();
engine.Evaluate("out$Achat_client=sapply(out$Achat_client,function(x) (if (x==1) {'Fidèle'} else {'Non Fidèle'}))").AsExpression();
engine.Evaluate("out$Achat_client=as.factor(unlist(out$Achat_client))").AsExpression();
// Creating new data base
DataFrame M1 =engine.Evaluate("M1=out").AsDataFrame();
// Creating the index of splitting
engine.Evaluate("val_index<-createDataPartition(M1$Achat_client,p=.75,list=FALSE)").AsExpression();
I got just an error in the last line of the code above :
Error in createDataPartition(M1$Achat_client, p = 0.75, list = FALSE) : y must have at least 2 data points
I searched and I find this logical solution here r- caret package error- createDataParition no observation.
So I remplaced M1$Achat_client by M1[[21]] and also by M1[,21] in other time just to try if it will work, But the error still shown !
Other thing, perphaps my origin script work very well in R in way of using M1$Achat_client . I'm surprised why in c# i have these kinds of error? Please how do you explain this?