I am trying to create a function to generate multiple Random forest models based on column value. Let suppose we :
df <- data.frame(Name= c('Aaron','Bob','Nik','Peter','George'),
Work=c('A','B','B','C','A')
,Age = c(45,28,64,27,54)
,cl = c(1,2,2,3,1))
Name Work Age cl
Aaron A 45 1
Bob B 28 2
Nik B 64 2
Peter C 27 3
George A 54 1
So, I have to subset data based on cl and then build models based on cl values like: In above example I have 3 cl values.So, first I will divide data into three subset and build three different models.
Name Work Age cl Name Work Age cl Name Work Age cl
Aaron A 45 1 Bob B 28 2 Peter C 27 3
George A 54 1 Nik B 64 2
I have used below function to do this:
for(i in unique(uk$v10v11)) {
nam <- paste("df", i, sep = ".")
assign(nam, uk[uk$v10v11==i,])
}
I want to make complete function where I can supply my df and it should build multiple models based on cl. I also want to tune parameters for the random forest from function itself for each model. Please help.